fix(chat): follow the assistant response to the bottom unless the user scrolls away - #23
Merged
Conversation
…r scrolls away Follow mode was a boolean flipped by every scroll event, including the app's own programmatic scrolls and passive layout shifts, so a mid-growth event could pin the viewport at the user prompt for the rest of the turn. It is now an explicit mode: growth of the transcript (any height change, not just message count or final text length, via a ResizeObserver on the content) keeps the viewport pinned to the bottom while following, and following stops only on genuine upward scroll intent (wheel, touch drag, ArrowUp/PageUp/Home) and resumes when the user returns to the bottom. Closes #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #19.
What broke
After submitting at the bottom, the viewport could stay anchored near the user prompt while the assistant response grew below the fold. Two compounding causes in
useChatSessionState:handleScrollransetIsUserScrolledUp(!isNearBottom())on every scroll event, including events fired by the app's own programmatic scrolls and passive layout shifts. One mid-growth event could flip follow mode off for the rest of the turn.chatMessages.lengthand the final message'scontent.length, missing tool cards, reasoning blocks, images/KaTeX, and any async reflow.Fix
New
useChatFollowScrollhook (extracted, DOM-tested):scrollToBottom()resumes following, so the existing "new messages below" button keeps working;isUserScrolledUp,hasNewMessagesBelow,scrollToBottomAndReset, and the load-older-at-top pagination path keep their exact public behavior (isUserScrolledUpis now!isFollowinginternally).Coverage
useChatFollowScroll.dom.bun.test.tsx(5 tests): growth pins to bottom; wheel-up stops follow; passive scroll events do not stop follow (the regression); returning to the bottom resumes;scrollToBottomresumes.useChatSessionState.test.tsstays green; both tsconfigs and eslint clean.Known limitation: dragging the scrollbar upward during active streaming doesn't emit wheel/touch/key intent, so follow resumes on the next content growth — wheel/touch/keyboard gestures, the common case, are all covered.