Skip to content

fix(app): prevent scroll snap while reading history during streaming - #40323

Closed
817811770 wants to merge 1 commit into
anomalyco:devfrom
817811770:fix-scroll-snap
Closed

817811770 wants to merge 1 commit into
anomalyco:devfrom
817811770:fix-scroll-snap

Conversation

@817811770

Copy link
Copy Markdown

Issue for this PR

Closes #40322

Type of change

  • Bug fix

What does this PR do?

The session view pins the scroll position to the bottom while a response is streaming. Two problems cause this:

  1. The auto-follow pause state (userScrolled in create-auto-scroll) only updates from scroll events inside a 250ms gesture window. Events outside that window are ignored, so the flag never turns on for some scroll gestures (wheel over nested scrollables, keyboard scrolling). With the flag off, every streamed token calls scrollToEnd() and yanks the viewport back to the bottom.
  2. Keyboard scrolling uses behavior: "smooth". The smooth animation gets cancelled by the per-token scrollToEnd before the viewport moves more than ~10px, so the threshold check never observes the user leaving the bottom and the state machine stays stuck.

Changes:

  • create-auto-scroll: track an atBottom flag from actual scroll positions (updated wherever userScrolled is updated) and require it before auto-following in the ResizeObserver path.
  • session.tsx: shouldAnchorBottom additionally requires autoScroll.atBottom(), so the virtualizer's scrollToEnd only runs while the user is at the bottom.
  • scroll-view: keyboard scrolling is now instant instead of smooth, so it cannot be cancelled mid-animation by content updates.

Result: scrolling up during streaming holds the viewport in place; scrolling back to the bottom resumes auto-follow.

How did you verify your code works?

  • typecheck passes for packages/ui and packages/app
  • existing scroll-view tests pass
  • rebuilt the desktop app locally and verified: scroll up during a streaming response holds position (mouse wheel and PageUp), scrolling back to the bottom resumes auto-follow
  • cherry-pick applies cleanly onto v1.18.11

Screenshots / recordings

Can be added on request.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: chat viewport snaps back to bottom while scrolling up during streaming response

2 participants