fix: preserve scroll position in session viewer when scrolled up#28
Merged
wesbillman merged 2 commits intomainfrom Feb 11, 2026
Merged
fix: preserve scroll position in session viewer when scrolled up#28wesbillman merged 2 commits intomainfrom
wesbillman merged 2 commits intomainfrom
Conversation
Track whether the user is near the bottom of the messages container using an onscroll handler. During polling, only auto-scroll to bottom if the user was already near the bottom (within 80px). Intentional scrolls (initial load, user sends a message) still force scroll to bottom unconditionally. - Add isNearBottom state and handleScroll listener on modal-content - Add scrollToBottomIfNear() that gates on isNearBottom - Replace scrollToBottom() with scrollToBottomIfNear() in poll() - Keep unconditional scrollToBottom() in loadSession() and sendMessage()
Replace the fragile isNearBottom heuristic (< 80px from bottom) with directional intent tracking using lastScrollTop comparison. This properly detects user-initiated upward scrolling across all input methods (mouse wheel, keyboard, touch, scrollbar drag). - Track userScrolledUp flag set when scrollTop decreases (upward scroll) - Clear flag when user scrolls back to exact bottom or on explicit scrollToBottom() calls (initial load, sending a message) - Remove magic 80px threshold that could misfire on short containers or miss intent on long ones
wesbillman
approved these changes
Feb 11, 2026
Collaborator
wesbillman
left a comment
There was a problem hiding this comment.
Nice! I'm always amazed at how hard this is for every chat app. 😂
loganj
added a commit
that referenced
this pull request
Feb 26, 2026
Adds dark mode with theme toggle and system preference detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When viewing a live session in the session modal, polling for new messages would always auto-scroll to the bottom — even if the user had intentionally scrolled up to read earlier content. This made it impossible to review previous messages during an active session.
Solution
Commit 1: Basic scroll preservation
Track whether the user is near the bottom of the messages container. During polling, only auto-scroll if the user was already at the bottom. Intentional scrolls (initial load, user sends a message) still force scroll to bottom unconditionally.
Commit 2: Replace pixel threshold with intent tracking
The initial implementation used a fragile 80px pixel threshold to determine "near bottom." This was replaced with directional intent tracking — comparing
scrollTopagainstlastScrollTopto detect when the user has scrolled upward.isNearBottom— true when within 80px of bottomuserScrolledUp— true when user scrolls upwardKey behavior:
userScrolledUp = truewhenscrollTopdecreases (user scrolled up)scrollToBottom()callsChanges
src/lib/SessionModal.svelte— scroll tracking logic in the messages container