Skip to content

fix: reliable auto-scroll with scroll-to-bottom button#150

Merged
devartifex merged 1 commit intodevartifex:masterfrom
dmbutko:fix/chat-auto-scroll
Apr 14, 2026
Merged

fix: reliable auto-scroll with scroll-to-bottom button#150
devartifex merged 1 commit intodevartifex:masterfrom
dmbutko:fix/chat-auto-scroll

Conversation

@dmbutko
Copy link
Copy Markdown
Contributor

@dmbutko dmbutko commented Apr 13, 2026

Fixes chat auto-scroll permanently disengaging when the user scrolls up, with no way to re-engage.

Root cause: CSS scroll-behavior: smooth caused a race condition - smooth scroll animations hadn't completed when the next position check fired, so isNearBottom() returned false mid-animation and auto-follow permanently disengaged.

Changes:

  • Replace position-only checks with explicit stickToBottom flag
  • Use Svelte tick() + instant scroll instead of CSS smooth scroll (no animation race)
  • Add a scroll-to-bottom arrow button that appears when scrolled up
  • Re-engage auto-follow automatically when user sends a new message
  • Use untrack() to prevent the sticky flag from being a reactive dependency in the scroll effect

Replace CSS scroll-behavior: smooth with explicit scroll tracking.
The old approach used isNearBottom() position checks that broke when
smooth scroll animations hadn't completed, permanently disengaging
auto-follow with no way to re-engage.

Changes:
- Track sticky state with explicit stickToBottom flag instead of
  position-only checks
- Use Svelte tick() + instant scroll (no animation race conditions)
- Add scroll-to-bottom arrow button when user scrolls up
- Re-engage auto-follow automatically when user sends a message
- Use untrack() to prevent stickToBottom from triggering the scroll
  effect as a dependency
- Wrap messages in container div for button positioning

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@devartifex devartifex left a comment

Choose a reason for hiding this comment

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

LGTM — Excellent fix for the auto-scroll race condition. The explicit stickToBottom flag with untrack() correctly decouples the scroll state from reactive tracking. Using tick() + instant scroll instead of CSS smooth scroll eliminates the animation race window. The scroll-to-bottom button has proper aria-label for accessibility. Re-engaging auto-follow on isWaiting is a nice UX touch. All 399 unit tests pass (check failure is a pre-existing coverage threshold issue).

@devartifex devartifex merged commit e69309f into devartifex:master Apr 14, 2026
5 of 6 checks passed
devartifex pushed a commit that referenced this pull request Apr 14, 2026
Replace CSS scroll-behavior: smooth with explicit scroll tracking.
The old approach used isNearBottom() position checks that broke when
smooth scroll animations hadn't completed, permanently disengaging
auto-follow with no way to re-engage.

Changes:
- Track sticky state with explicit stickToBottom flag instead of
  position-only checks
- Use Svelte tick() + instant scroll (no animation race conditions)
- Add scroll-to-bottom arrow button when user scrolls up
- Re-engage auto-follow automatically when user sends a message
- Use untrack() to prevent stickToBottom from triggering the scroll
  effect as a dependency
- Wrap messages in container div for button positioning

Co-authored-by: Dmitry Butko <dmitrybutko@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants