Skip to content

fix(tui): prevent scroll snap when reading history during LLM response#21343

Open
divitkashyap wants to merge 2 commits intoanomalyco:devfrom
divitkashyap:fix/tui-scroll-snap-4196
Open

fix(tui): prevent scroll snap when reading history during LLM response#21343
divitkashyap wants to merge 2 commits intoanomalyco:devfrom
divitkashyap:fix/tui-scroll-snap-4196

Conversation

@divitkashyap
Copy link
Copy Markdown

Issue for this PR

Type of change

  • Bug fix

What does this PR do?

When a user scrolls up to read chat history while an LLM is still streaming, the view snaps back to the bottom on every token update. This is because stickyScroll={true} on the message scrollbox forces scroll-to-bottom regardless of user scroll state.

The fix adds a userScrolledUp signal that tracks when the user has manually scrolled away from the bottom. The stickyScroll prop is now reactive (!userScrolledUp()), so auto-scroll only engages when the user is at the bottom.

Upward scroll commands (Page Up, Line Up, Half Page Up, First Message) set the flag. Commands that return to bottom (toBottom(), Last Message) and session sync reset it.

How did you verify your code works?

  • bun run typecheck passes in all 13 packages
  • Logic review — changes follow existing TUI patterns and mirror packages/ui/src/hooks/create-auto-scroll.tsx from the web app, which implements the same behavior for the web client

Checklist

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

When a user scrolls up to read chat history while an LLM is still
streaming, the view would snap back to the bottom on every token
update due to stickyScroll=true always forcing scroll-to-bottom.

This change tracks user scroll state via a userScrolledUp signal and
makes stickyScroll reactive - only auto-scrolling when the user is
at the bottom. User scroll commands (page up, line up, first message)
set the flag to pause auto-scroll, while toBottom() and last message
reset it to resume.

Fixes anomalyco#4196
@divitkashyap
Copy link
Copy Markdown
Author

All checks passed! @thdxr could you take a look? This fixes #4196.

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.

Reading chat history during LLM responses re-snaps the history

1 participant