Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 14, 2025

This PR attempts to address Issue #7974 by improving the auto-scroll behavior in the chat view.

Problem

Users were unable to read earlier parts of LLM output because the window would automatically scroll to the bottom whenever new content arrived, interrupting their reading experience.

Solution

Implemented a dual-state tracking system that:

  • Tracks when users manually scroll up to read content (userHasScrolledUpRef)
  • Disables auto-scroll when users scroll up
  • Only re-enables auto-scroll when users explicitly indicate they want to follow new output by:
    • Scrolling down while at the bottom of the view
    • Clicking the "scroll to bottom" button
    • Starting a new task

Changes

  • Added userHasScrolledUpRef to track manual scroll state
  • Modified wheel event handler to detect scroll direction and user intent
  • Updated atBottomStateChange callback to respect user scroll preferences
  • Reset scroll state appropriately when tasks change

Testing

  • All existing tests pass
  • Linting passes
  • Type checking passes

Fixes #7974

Feedback and guidance are welcome!


Important

Improves chat view scroll behavior in ChatView.tsx by tracking user scroll actions to manage auto-scroll state.

  • Behavior:
    • Introduces userHasScrolledUpRef in ChatView.tsx to track manual scroll actions.
    • Disables auto-scroll when user scrolls up; re-enables when user scrolls to bottom or clicks "scroll to bottom".
    • Resets scroll state on new task initiation.
  • Functions:
    • Modifies handleWheel to detect scroll direction and adjust disableAutoScrollRef and userHasScrolledUpRef.
    • Updates atBottomStateChange to respect userHasScrolledUpRef.
  • Misc:
    • All existing tests, linting, and type checks pass.

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

- Added userHasScrolledUpRef to track when user manually scrolls up
- Modified wheel event handler to detect scroll direction
- Only re-enable auto-scroll when user explicitly scrolls down to bottom
- Prevent auto-scroll from re-enabling when reaching bottom passively
- Reset scroll state when starting new tasks

Fixes #7974
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 14, 2025 16:24
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 14, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

if (wheelEvent.deltaY < 0) {
// User scrolled up - disable auto-scroll and mark that user has scrolled up
disableAutoScrollRef.current = true
userHasScrolledUpRef.current = true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? We're using refs () that don't trigger re-renders, but checking them in callbacks that might use stale values. Could this create a race condition where (line 1900) reads an outdated value?

Maybe consider using state instead of refs, or ensure the callback always has the latest ref value?

const prevExpandedRowsRef = useRef<Record<number, boolean>>()
const scrollContainerRef = useRef<HTMLDivElement>(null)
const disableAutoScrollRef = useRef(false)
const userHasScrolledUpRef = useRef(false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dual-state tracking system with both and works, but could we simplify this? They seem to track similar concepts - maybe a single state enum like would be clearer?

userRespondedRef.current = false
// Reset scroll state for new task
disableAutoScrollRef.current = false
userHasScrolledUpRef.current = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that we're resetting scroll state for new tasks! However, this critical UX feature would benefit from test coverage. Could we add tests verifying:

  • Scroll state preservation when user scrolls up
  • Auto-scroll resumption when scrolling to bottom
  • Proper state reset on new tasks

const wheelEvent = event as WheelEvent

if (wheelEvent.deltaY && wheelEvent.deltaY < 0) {
if (scrollContainerRef.current?.contains(wheelEvent.target as Node)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation of the scroll direction detection! Consider adding a comment block here explaining the dual-state tracking system for future maintainers, as the interaction between and might not be immediately obvious.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 14, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 15, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Sep 15, 2025
@daniel-lxs
Copy link
Member

#7974 (comment)

@daniel-lxs daniel-lxs closed this Sep 16, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Sep 16, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 16, 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 PR - Needs Preliminary Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Allow reading of output even though new output is still being appended

4 participants