Skip to content

fix(chat): keep viewport pinned to bottom while assistant streams#25

Merged
Nkburdick merged 1 commit intomainfrom
fix/chat-streaming-scroll-keepup
May 4, 2026
Merged

fix(chat): keep viewport pinned to bottom while assistant streams#25
Nkburdick merged 1 commit intomainfrom
fix/chat-streaming-scroll-keepup

Conversation

@Nkburdick
Copy link
Copy Markdown
Owner

@Nkburdick Nkburdick commented May 1, 2026

Summary

Fixes the chat scroller dropping behind the streaming text. While the assistant streams a long response token-by-token, the existing auto-scroll \$effect (length-based) doesn't fire — so lines drift below the viewport and the user has to manually scroll.

Why

Caught 2026-04-30 EOD when Nick asked "So you said the chat streaming scroller was already implemented, right?" — verifying revealed the original implementation only handled the new-message-append case. Streaming mutates the assistant message's content field within the same array entry; messages.length is unchanged, so the \$effect at line 134 silently skips the streaming case.

What changed

In the SSE token event branch of both chat thread files, after applying the content patch:

  • If user is at bottom (isScrolledToBottom) → tick().then(() => scrollTop = scrollHeight)
  • Else → hasNewMessages = true (lights up the existing pill, lets user tap to catch up)

Identical change in both files since they have identical streaming structure:

  • src/routes/projects/[slug]/chats/[threadId]/+page.svelte
  • src/routes/areas/[slug]/chats/[threadId]/+page.svelte

What's NOT changed

  • The append-path \$effect still handles brand-new messages
  • The done-event post-stream scroll still runs
  • User-scrolled-up state continues to surface the pill (no auto-yank)

Test plan

  • bun run check clean (0 errors, 3 pre-existing warnings unrelated)
  • Send a long prompt to an assistant and watch it stream — viewport should track the trailing line
  • Mid-stream, scroll up manually — verify auto-scroll stops, pill appears, taps to bottom
  • Compare project + area chat — both behave identically

Notes

  • After merge, run cd /opt/oracle-stack && docker compose pull oracle && docker compose up -d oracle on KVM2 (oracle-app deploy is manual until pai-p3-infra-007 ships).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced scroll behavior during message streaming across chat interfaces. The viewport now automatically maintains position at the bottom when new content arrives, and displays a "new messages" indicator when users have scrolled up, ensuring better visibility of incoming messages.

Bug: while an assistant response is streaming token-by-token, the chat
viewport doesn't follow the new content. Lines drift past the bottom and
the user has to manually scroll. Found while reviewing 2026-04-30 polish
session — the existing $effect at line 134 watches messages.length, but
streaming only mutates the assistant message's `content` field, never
appending a new message. So the auto-scroll path silently skips streaming.

Fix: in the SSE token-event branch (line 268), after applying the content
patch, scroll the container to the bottom IF the user is still at the
bottom. If they've scrolled up, set hasNewMessages so the pill renders —
mirrors the new-message-append behavior.

Wraps the scroll in tick() so we read scrollHeight after Svelte flushes
the messages-array reactive update to the DOM.

Applied to both project (`/projects/[slug]/chats/[threadId]/+page.svelte`)
and area (`/areas/[slug]/chats/[threadId]/+page.svelte`) chat thread
files — both have identical streaming structures.

DOES NOT FIRE on:
- New message append (existing $effect already handles)
- 'done' event (existing post-stream scroll already handles)
- User scrolled-up state (defers to pill flow)

Closes the streaming-scroll gap I miss-marked as "already implemented"
when first scanning the polish bundle. Same task entry that was prematurely
closed now reopened with a real fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56bb03e9-594e-4879-b92e-6e655165adc7

📥 Commits

Reviewing files that changed from the base of the PR and between 14789cd and 2145b9d.

📒 Files selected for processing (2)
  • src/routes/areas/[slug]/chats/[threadId]/+page.svelte
  • src/routes/projects/[slug]/chats/[threadId]/+page.svelte

📝 Walkthrough

Walkthrough

Two chat thread pages—one in the areas route and one in the projects route—now explicitly manage scroll behavior during SSE token streaming events, keeping the viewport pinned when at the bottom or marking new messages when scrolled up.

Changes

Cohort / File(s) Summary
Chat Thread Scroll Management
src/routes/areas/[slug]/chats/[threadId]/+page.svelte, src/routes/projects/[slug]/chats/[threadId]/+page.svelte
Added scroll behavior handling during token streaming: if user is at the bottom, schedules a scrollTop update to keep viewport pinned to growing content; otherwise sets hasNewMessages flag to surface new message notifications.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hopping through the tokens, keeping chat in view,
When the bottom calls, we scroll on through,
But if you drift up to see what's new,
A message appears—a little "ping" just for you! 💬✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(chat): keep viewport pinned to bottom while assistant streams' directly and clearly summarizes the main change—fixing viewport scroll behavior during token streaming in chat.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chat-streaming-scroll-keepup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@Nkburdick Nkburdick merged commit a77104f into main May 4, 2026
2 checks passed
@Nkburdick Nkburdick deleted the fix/chat-streaming-scroll-keepup branch May 4, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant