fix: scroll to bottom of conversation on thread switch#157
Closed
HUQIANTAO wants to merge 1 commit into
Closed
Conversation
Double-rAF defer scrollIntoView until after visibleTurnCount re-derives and the extra turns have been painted, preventing the scroll position from getting stuck mid-content on thread switch.
Collaborator
|
目前先不建议直接合入,这条 PR 也会先关闭。 具体原因:
建议怎么改:
这次先关闭,避免继续挂在错误的目标分支上。 |
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.
Problem
When switching between conversations via the sidebar, the message timeline does not scroll to the latest messages. Instead, the viewport lands somewhere in the middle of the conversation, leaving the user disoriented.
Root Cause
A race condition in the
useTimelineScrollhook between twouseEffectblocks insrc/renderer/src/components/chat/use-timeline-scroll.ts:Hard reset effect (triggered by
activeThreadIdchange): callsendRef.current?.scrollIntoView()synchronously. At this pointvisibleTurnCountReact state is still stale from the previous conversation — only a subset of turns are rendered in the DOM.Re-derive visible count effect (also triggered by
activeThreadIdchange): callssetVisibleTurnCount(deriveTimelineVisibleTurnCount(...)), which queues an async state update that re-renders with more turns prepended above the viewport.Because the scroll fires before the visible turn count reconciles, the content area grows taller after the scroll, pushing the scroll position away from the bottom.
Fix
Defer the
scrollIntoViewcall using a doublerequestAnimationFrame, ensuring it runs aftervisibleTurnCounthas been re-derived and the additional turns have been painted:Files Changed
src/renderer/src/components/chat/use-timeline-scroll.ts— defer scroll in thread-switch effect (+9, -1)Testing