fix(chat): keep viewport pinned to bottom while assistant streams#25
fix(chat): keep viewport pinned to bottom while assistant streams#25
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
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
contentfield within the same array entry;messages.lengthis unchanged, so the\$effectat line 134 silently skips the streaming case.What changed
In the SSE
tokenevent branch of both chat thread files, after applying the content patch:isScrolledToBottom) →tick().then(() => scrollTop = scrollHeight)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.sveltesrc/routes/areas/[slug]/chats/[threadId]/+page.svelteWhat's NOT changed
\$effectstill handles brand-new messagesdone-event post-stream scroll still runsTest plan
bun run checkclean (0 errors, 3 pre-existing warnings unrelated)Notes
cd /opt/oracle-stack && docker compose pull oracle && docker compose up -d oracleon KVM2 (oracle-app deploy is manual untilpai-p3-infra-007ships).🤖 Generated with Claude Code
Summary by CodeRabbit