-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: prevent chat auto-scroll when user is reading previous messages #8614
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
Conversation
- Add tracking of scroll position before message updates - Only auto-scroll if user was already at bottom before new messages - Improve scroll detection for both wheel and touch events - Disable auto-scroll on any manual scroll action, not just scrolling up - Re-enable auto-scroll only when user manually scrolls back to bottom Fixes #8612
| // Track if user was at bottom before messages update | ||
| useEffect(() => { | ||
| wasAtBottomBeforeUpdateRef.current = isAtBottom | ||
| }, [isAtBottom, groupedMessages.length]) // Capture state before the update |
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.
Race condition: This effect runs AFTER groupedMessages.length changes, but the ref is supposed to capture the state BEFORE the update. When new messages arrive, both this effect and the auto-scroll effect (lines 1404-1418) will run in the same render cycle, making wasAtBottomBeforeUpdateRef.current reflect the state AFTER the update, not before.
To fix this, remove groupedMessages.length from the dependency array and capture the state in a useLayoutEffect before the DOM updates, or capture it just before the state change that triggers the message update.
| atBottomStateChange={(atBottom: boolean) => { | ||
| setIsAtBottom(atBottom) | ||
| if (atBottom) { | ||
| // User scrolled back to bottom, re-enable auto-scroll | ||
| disableAutoScrollRef.current = false |
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.
Logic bug: When atBottom is true, this unconditionally re-enables auto-scroll. This creates a race condition with the wheel handler:
- User at bottom scrolls up slightly (< 10px threshold)
- Wheel handler disables auto-scroll (line 1438)
- Virtuoso still considers user "at bottom" (within threshold)
- This callback re-enables auto-scroll immediately
Result: User's scroll intent is ignored if they stay within the 10px threshold. To fix, only re-enable auto-scroll when transitioning from false to true (user actively scrolled back to bottom), not when already at bottom:
| atBottomStateChange={(atBottom: boolean) => { | |
| setIsAtBottom(atBottom) | |
| if (atBottom) { | |
| // User scrolled back to bottom, re-enable auto-scroll | |
| disableAutoScrollRef.current = false | |
| atBottomStateChange={(atBottom: boolean) => { | |
| const wasAtBottom = isAtBottom | |
| setIsAtBottom(atBottom) | |
| if (atBottom && !wasAtBottom) { | |
| // User scrolled back to bottom from above, re-enable auto-scroll | |
| disableAutoScrollRef.current = false | |
| } | |
| // Show scroll-to-bottom button when auto-scroll is disabled and not at bottom | |
| setShowScrollToBottom(disableAutoScrollRef.current && !atBottom) | |
| }} |
Summary
This PR fixes the auto-scroll behavior in the chat view that was preventing users from reading previous messages while Roo Code is generating responses.
Problem
As reported in #8612, when Roo Code sends messages, the chat automatically scrolls to the bottom, making it impossible for users to scroll up and read or copy earlier parts of the conversation until the bot fully stops responding.
Solution
The fix introduces an improved scroll detection mechanism that:
Changes Made
wasAtBottomBeforeUpdateRefto track scroll position before message updateshandleWheelto detect any deliberate scroll action (not just scrolling up)handleTouchMovefor mobile touch scrolling supportTesting
Fixes #8612
Important
Improves chat auto-scroll behavior in
ChatView.tsxto respect user reading previous messages and adds mobile touch support.ChatView.tsx.wasAtBottomBeforeUpdateRefto track scroll position before updates.handleWheeland addshandleTouchMoveto detect user scroll actions.ChatView.tsx.This description was created by
for 41191a1. You can customize this summary. It will automatically update as commits are pushed.