-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: improve autoscroll behavior for thinking sections #7880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1419,6 +1419,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| } | ||
| }, []) | ||
|
|
||
| // Track if we're currently streaming a thinking/reasoning message | ||
| const isStreamingThinking = useMemo(() => { | ||
| const lastMessage = modifiedMessages.at(-1) | ||
| return lastMessage?.say === "reasoning" && lastMessage?.partial === true | ||
| }, [modifiedMessages]) | ||
|
|
||
| // Enhanced scroll behavior for thinking sections | ||
| useEffect(() => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice this new effect duplicates the scroll logic from lines 1399-1409. Both call |
||
| // When streaming thinking content, check if user has manually scrolled | ||
| // If they haven't, continue auto-scrolling | ||
| // If they have (disableAutoScrollRef.current is true), respect their choice | ||
| if (isStreamingThinking && !disableAutoScrollRef.current) { | ||
| // Continue auto-scrolling for thinking content if user hasn't intervened | ||
| scrollToBottomSmooth() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
| }, [isStreamingThinking, scrollToBottomSmooth]) | ||
|
|
||
| useEvent("wheel", handleWheel, window, { passive: true }) // passive improves scrolling performance | ||
|
|
||
| // Effect to handle showing the checkpoint warning after a delay | ||
|
|
@@ -1903,6 +1920,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| atBottomStateChange={(isAtBottom: boolean) => { | ||
| setIsAtBottom(isAtBottom) | ||
| if (isAtBottom) { | ||
| // Re-enable autoscroll when user scrolls to bottom | ||
| // This is the key fix: users can scroll up to read thinking content, | ||
| // and autoscroll resumes when they scroll back down | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is excellent! Consider adding a similar explanatory comment near the |
||
| disableAutoScrollRef.current = false | ||
| } | ||
| setShowScrollToBottom(disableAutoScrollRef.current && !isAtBottom) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving this thinking detection logic closer to where
isStreamingis computed (around line 516) for better code organization. This would group related streaming logic together.