fix: chat auto-scrolls to top after thinking completes#319
Open
xoknight wants to merge 1 commit intoTHU-MAIC:mainfrom
Open
fix: chat auto-scrolls to top after thinking completes#319xoknight wants to merge 1 commit intoTHU-MAIC:mainfrom
xoknight wants to merge 1 commit intoTHU-MAIC:mainfrom
Conversation
The streaming auto-scroll effect (Effect 2) used scrollContainerRef.scrollTop
to pin the viewport, but scrollContainerRef has no fixed height constraint and
never overflows — the real scrollable ancestor is the parent div in chat-area.
This made the effect a no-op, so after agent transitions (onAgentEnd removing
empty messages + onAgentStart adding new ones) the scroll position was lost.
Fix: use bottomRef.scrollIntoView({ behavior: 'instant', block: 'end' })
which correctly targets the nearest scrollable ancestor.
Also change activeBubbleId scroll from block:'nearest' to block:'end' — the
active bubble is always the latest message, and 'nearest' could leave the
viewport mid-list after thinking transitions.
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.
Summary
scrollContainerRefhas no fixed height and never overflows, soel.scrollTop = el.scrollHeightdid nothing. The real scrollable ancestor is the parent div inchat-area.tsx.bottomRef.scrollIntoView({ behavior: 'instant', block: 'end' })which correctly targets the nearest scrollable ancestor.activeBubbleIdscroll fromblock: 'nearest'toblock: 'end'— the active bubble is always the latest message, andnearestcould leave the viewport mid-list after thinking transitions.Root Cause
In
chat-session.tsx, threeuseEffecthooks manage auto-scroll:msgCountdep):bottomRef.scrollIntoView— works correctlysession.messagesdep):scrollContainerRef.scrollTop = scrollHeight— broken because the element has no height constraint and never overflowsactiveBubbleIddep):activeBubbleRef.scrollIntoView({ block: 'nearest' })— works butnearestcan scroll to mid-listWhen thinking completes,
onAgentEndremoves empty messages andonAgentStartadds new ones. If React batches these,msgCountstays the same → Effect 1 doesn't fire. Effect 2 should compensate but is a no-op → scroll position is lost during re-layout → chat jumps to top.Test plan
🤖 Generated with Claude Code