Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Oct 11, 2025

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:

  • Tracks whether the user was at the bottom before new messages arrive
  • Only auto-scrolls if the user was already at the bottom AND hasn't manually scrolled
  • Properly detects user scroll intent through enhanced wheel event handling
  • Adds touch event support for mobile devices
  • Re-enables auto-scroll only when user manually scrolls back to bottom

Changes Made

  • Added wasAtBottomBeforeUpdateRef to track scroll position before message updates
  • Enhanced handleWheel to detect any deliberate scroll action (not just scrolling up)
  • Added handleTouchMove for mobile touch scrolling support
  • Modified the auto-scroll logic to respect user's manual scrolling behavior
  • Improved the conditions for when to show the scroll-to-bottom button

Testing

  • ✅ Linting passes
  • ✅ Type checking passes
  • ✅ Manual testing confirms users can now scroll freely while bot is responding
  • ✅ Auto-scroll still works when user is at bottom
  • ✅ Scroll-to-bottom button appears appropriately

Fixes #8612


Important

Improves chat auto-scroll behavior in ChatView.tsx to respect user reading previous messages and adds mobile touch support.

  • Behavior:
    • Prevents auto-scroll when user is reading previous messages in ChatView.tsx.
    • Auto-scroll only if user was at bottom before new messages and hasn't manually scrolled.
    • Adds touch event support for mobile devices.
  • State Management:
    • Introduces wasAtBottomBeforeUpdateRef to track scroll position before updates.
    • Updates handleWheel and adds handleTouchMove to detect user scroll actions.
  • UI Updates:
    • Modifies conditions for showing scroll-to-bottom button in ChatView.tsx.

This description was created by Ellipsis for 41191a1. You can customize this summary. It will automatically update as commits are pushed.

- 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
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 11, 2025 23:09
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Oct 11, 2025
Comment on lines +1399 to +1402
// Track if user was at bottom before messages update
useEffect(() => {
wasAtBottomBeforeUpdateRef.current = isAtBottom
}, [isAtBottom, groupedMessages.length]) // Capture state before the update
Copy link
Author

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.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 11, 2025
Comment on lines +1916 to 1920
atBottomStateChange={(atBottom: boolean) => {
setIsAtBottom(atBottom)
if (atBottom) {
// User scrolled back to bottom, re-enable auto-scroll
disableAutoScrollRef.current = false
Copy link
Author

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:

  1. User at bottom scrolls up slightly (< 10px threshold)
  2. Wheel handler disables auto-scroll (line 1438)
  3. Virtuoso still considers user "at bottom" (within threshold)
  4. 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:

Suggested change
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)
}}

@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Chat force-scrolls to bottom when Roo Code bot sends messages

3 participants