Fix/chat scroll continuous streaming#119
Open
santinoo1919 wants to merge 7 commits intodarkresearch:mainfrom
Open
Fix/chat scroll continuous streaming#119santinoo1919 wants to merge 7 commits intodarkresearch:mainfrom
santinoo1919 wants to merge 7 commits intodarkresearch:mainfrom
Conversation
- Scroll immediately (non-animated) when content arrives during active scrolling - Extend timeout to keep auto-scroll flag true as long as content keeps arriving - Prevent scroll button from appearing during streaming - Simplify code by removing unnecessary retry logic Fixes issue where auto-scroll would pause randomly during streaming, causing the scroll-to-bottom button to appear and interrupting the UX.
- Remove dual state tracking (useState + useRef) that caused sync issues - Eliminate competing timeouts that created race conditions - Simplify scroll trigger logic to single code path - Remove Promise wrapper from scrollToBottom for cleaner API - Better support for rapid streaming updates with instant scrolls - Reduce complexity from 190 to 170 lines
- Track scroll direction to distinguish user scroll-up from programmatic scroll - Only cancel auto-scroll when user scrolls away from bottom (scrollY decreasing) - Fixes 'inertia back to bottom' issue when scrolling up during streaming - Preserves button click scroll-to-bottom functionality
…tion - Move checkIfAtBottom outside component as pure function - Add clearTimeoutSafe helper to reduce code duplication - Add isAtBottomRef to prevent stale closures in callbacks - Remove unnecessary useMemo wrapper - Add scroll direction detection to cancel auto-scroll when user scrolls up - Fix unused contentWidth parameter KNOWN ISSUE: Scroll button flickers 3-4 times when scrolling up during fast streaming. This is due to a race condition where handleContentSizeChange restarts auto-scroll before isAtBottomRef is updated. Fix requires adding userScrolledUpRef lock to prevent auto-scroll restart after user scrolls up. Will be addressed in follow-up PR.
- Add SCROLL_DIRECTION_THRESHOLD (2px) to detect scroll direction changes - Only cancel auto-scroll when user scrolls up by more than 2px - Prevents false positives during rapid content updates during streaming - Fixes scroll button flickering issue when scrolling up during fast streaming
Add changeset documenting the chat scroll behavior improvements that fix issue darkresearch#54. The changeset covers all commits in this PR related to auto-scroll fixes.
- Add contentSizeChangeTimeoutRef to track previously untracked timeout - Add cleanup useEffect to clear all timeouts on component unmount - Prevents React warnings about state updates on unmounted components - Prevents memory leaks from pending timeouts - Addresses Vercel bot feedback
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.
Description
Fixes #54 - Chat scroll behavior now properly handles auto-scrolling during streaming without interrupting user's ability to browse chat history.
Problem:
Solution:
Completely refactored
useSmartScrollhook with:Key Changes:
useMemo, moved pure functions outside)clearTimeoutSafehelper to reduce code duplicationType of Change
Release
Is this a release? No
Testing
Acceptance Criteria Met:
Checklist
Note: Manual testing completed. Automated tests for scroll behavior would require E2E testing setup which is beyond scope of this bug fix.