Fix/chat window scroll#445
Open
Madhavi1108 wants to merge 12 commits into
Open
Conversation
|
@Madhavi1108 is attempting to deploy a commit to the Darshan's projects Team on Vercel. A member of the Team first needs to authorize it. |
imDarshanGK
requested changes
Jun 22, 2026
imDarshanGK
left a comment
Owner
There was a problem hiding this comment.
@Madhavi1108 add video demo
Author
|
Hi @imDarshanGK , WhatsApp.Video.2026-06-25.at.12.38.43.mp4 |
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
This PR fixes an issue where the chat window would automatically scroll to the bottom whenever the
messagesarray changed, even if the modification only affected an existing message (such as edits or reactions). The updated implementation introduces context-aware auto-scroll logic that only scrolls when appropriate, preserving the user's current reading position during edits while maintaining the expected behavior for new messages and session changes.The solution leverages state tracking with React refs, conditional scroll detection, and comprehensive regression tests to provide a smoother and more predictable chat experience.
Closes #248
Type of Change
Checklist
What Was Implemented
Auto-Scroll Logic Fix
Refactored the chat window's automatic scrolling behavior to avoid unnecessary viewport jumps.
Updated Component
ChatWindow.jsxPreviously, scrolling was triggered unconditionally whenever the
messagesarray changed, causing the viewport to jump to the bottom even when editing older messages.The new implementation performs context-aware checks before scrolling.
Previous State Tracking
Introduced
useRef-based tracking to compare the previous and current chat state.The implementation maintains references for:
This enables the component to distinguish between legitimate append operations and in-place updates.
New Message Detection
Automatic scrolling now occurs when a new message is appended to the conversation.
If the current message count exceeds the previously recorded count:
This maintains the natural experience during active conversations.
Session Change Handling
Added detection for active chat session changes.
When users switch between conversations:
This preserves expected navigation behavior.
Initial Load Support
Retained automatic scrolling during the first render of a conversation.
On initial message loading:
This behavior remains unchanged from the intended user experience.
Streaming Message Support
Continued support for streaming responses.
If the final message is actively streaming:
This preserves the usability of incremental response rendering.
Stable Position During Message Edits
Modified the scrolling behavior for updates affecting existing messages.
When operations such as:
occur without increasing the message count, the current scroll position is preserved.
This prevents disruptive jumps while reviewing historical conversations.
Regression Test Suite
Added automated tests covering the updated scrolling behavior.
New Test
ChatWindow.test.jsxThe test suite validates:
These tests protect against future regressions.
Test Validation
Executed the frontend test suite to verify the implementation.
Verification
npx vitest runThe updated scrolling logic and regression tests execute successfully within the project's testing framework.
Benefits
Acceptance Criteria
Technical Notes
useRefto maintain previous message counts and session identifiers, allowing the component to differentiate between appended messages and in-place updates.scrollIntoView()to execute, preserving the user's current reading position.ChatWindow.test.jsxregression suite validates all supported scrolling scenarios and protects the behavior from future changes.