Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(chat): only auto-scroll when user is already at bottom of chat #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025

Conversation

hugodutka
Copy link
Collaborator

Addresses #9

@hugodutka hugodutka requested a review from BrunoQuaresma May 26, 2025 10:36
@BrunoQuaresma
Copy link
Contributor

I think we can simplify this logic a lot. We can just check if before scrolling on receiving a new message, if the current scroll height is less than the actual height. Makes sense? I think this solution is way to complex. Feel free if you want me to implement that and show you what I'm talking about.

@hugodutka
Copy link
Collaborator Author

@BrunoQuaresma that makes sense. Feel free to take a stab at it, thanks!

Copy link
Contributor

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

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

I think it is ok for now 👍

@hugodutka
Copy link
Collaborator Author

To add context why we're not pursuing a simpler approach: to determine if we should scroll down we need to check whether a user is scrolled to the bottom BEFORE adding a new message to the virtual DOM, but both useEffect and useLayoutEffect run AFTER. I don't know a React hook that would fit this use case and let us simplify the logic I initially submitted.

@hugodutka hugodutka merged commit 4d05971 into main May 27, 2025
1 check passed
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.

2 participants