Skip to content
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

#2548, #2430 - Fix chat scroll related bugs #2590

Closed
wants to merge 3 commits into from

Conversation

SebinSong
Copy link
Collaborator

@SebinSong SebinSong commented Feb 6, 2025

closes #2548
closes #2430

[Fix for issue 2548]

scroll-issue-fix-1.mp4

[Fix for issue 2430]

scroll-issue-fix-2.mp4

Even though I still have not demystified 100% of How message states in chatroom are managed / entire steps of how message states are initialized, I tried my best to ensure these updates don't end up breaking any existing behavior the chatroom has. Thanks.

@SebinSong SebinSong self-assigned this Feb 6, 2025
Copy link

cypress bot commented Feb 7, 2025

group-income    Run #3887

Run Properties:  status check passed Passed #3887  •  git commit c29216b7e6 ℹ️: Merge 2fe7f8503b4441782d05dbdda178df35a3ddbb81 into 5b89d7022aca2200db3d2fb01f94...
Project group-income
Branch Review sebin/task/#2548-chat-scrolling-bug
Run status status check passed Passed #3887
Run duration 10m 50s
Commit git commit c29216b7e6 ℹ️: Merge 2fe7f8503b4441782d05dbdda178df35a3ddbb81 into 5b89d7022aca2200db3d2fb01f94...
Committer Sebin Song
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 112
View all changes introduced in this branch ↗︎

@SebinSong SebinSong changed the title [WIP] #2548, #2430 - Fix chat scroll related bug #2548, #2430 - Fix chat scroll related bug Feb 7, 2025
@@ -166,10 +166,13 @@ const onChatScroll = function () {

for (let i = this.messages.length - 1; i >= 0; i--) {
const msg = this.messages[i]
const msgEl = this.$refs[msg.hash][0].$el
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

DRYing reference to a particular message DOM element here.

Comment on lines -552 to +561
eleTarget.scrollIntoView({ behavior: this.isReducedMotionMode ? 'instant' : 'smooth' })
eleMessage.scrollIntoView({ behavior: this.isReducedMotionMode ? 'instant' : 'smooth' })
eleMessage.classList.add('c-focused')
setTimeout(() => {
eleMessage.classList.remove('c-focused')
}, 1500)
} else {
eleTarget.scrollIntoView()
eleMessage.scrollIntoView()
Copy link
Collaborator Author

@SebinSong SebinSong Feb 7, 2025

Choose a reason for hiding this comment

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

This part is the fix for #2548. (It's unclear what the original intention here was but) eleTarget here is a message placed above the actual target message and eleTarget.scrollIntoView(...) leads to not fully scrolling to the target message. (especially when that previous message has associated file-attachments and takes up large space in the DOM). So made a fix here.

Comment on lines -861 to -877

// NOTE: we do want the 'c-focused' animation if there is a message-scroll query.
if (events.length) {
// NOTE: if 'messageHashToScroll' was not there in the messages of the contract state
// we need to retrieve more events, and render to scroll to that message
this.updateScroll(messageHashToScroll, Boolean(mhash))
} else {
// NOTE: we need to scroll to the message first in order to no more infiniteHandler is called
await this.updateScroll(messageHashToScroll, Boolean(mhash))

if (mhash) {
// NOTE: delete mhash in the query after scroll and highlight the message with mhash
const newQuery = { ...this.$route.query }
delete newQuery.mhash
this.$router.replace({ query: newQuery })
}
}
Copy link
Collaborator Author

@SebinSong SebinSong Feb 7, 2025

Choose a reason for hiding this comment

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

This logic here handles scrolling to a particular message after message states are initialized. And moving this logic to below this.ephemeral.messagesInitiated = true is the fix for issue #2430 .
I noticed infiniteHandler() and renderMoreMessages() methods are called multiple times throughout the entire chatroom initialization process (which honestly I have not been able to figure out yet exactly from where and why..) and observed that executing scrolling logic here looked premature most of the time.
So moved this logic and it fixed the mhash issue.

@SebinSong SebinSong changed the title #2548, #2430 - Fix chat scroll related bug #2548, #2430 - Fix chat scroll related bugs Feb 7, 2025
Comment on lines -191 to +194
if (this.ephemeral.scrolledDistance > ignorableScrollDistanceInPixel) {
if (curScrollTop > ignorableScrollDistanceInPixel) {
Copy link
Collaborator Author

@SebinSong SebinSong Feb 7, 2025

Choose a reason for hiding this comment

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

This is part of the fix for #2548 too.
Using this.ephemeral.scrolledDistance here is apparently wrong. If we see L165 below:

const scrollTopMax = this.$refs.conversation.scrollHeight - this.$refs.conversation.clientHeight
this.ephemeral.scrolledDistance = scrollTopMax - curScrollTop

ephemeral.scrolledDistance isn't actually calculating scrollED distance but rather measuring srollABLE distance. This value gets closer to 0 as the chatroom scrolls closer to the bottom(the latest message) and as a result the logic in below if block (which saves the current scroll position of the chatroom)

if (curScrollTop > ignorableScrollDistanceInPixel) { ... }

ends up not getting executed for a couple of most recent messages, in some cases.
So replaced it with currScrollTop (which is the correct variable that calculates currently scrollED distance)


I didn't go ahead and update this.ephemeral.scrolledDistance itself in this PR because, this might cause unexpected bugs in other places where this is currently used.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Great work @SebinSong!

I can confirm that #2430 seems to be closed, however #2548 still seems to be an issue, and there are two problems:

Problem 1: Scrolling to end still doesn't work at certain viewport sizes

When the browser window is a certain height/width, it still doesn't seem to work:

broken.compressed.mov

Problem 2: Remembering scroll position now completely broken

The behavior we want is that if we're scrolled near the end, then when we switch back to that channel, it takes us all the way to the very end.

However, if we've scrolled kind of far up, then upon switching channels back, we should scroll to where we were.

With this PR now it seems that that behavior is completely broken, as it no longer remembers scroll position in my testing in FFDev.

@SebinSong
Copy link
Collaborator Author

@taoeffect
I'm actually closing this PR and just created a separate PR for #2430 in here, As I think #2548 needs a closer investigation.

I will probably spend some more time on it in the future and send a separate PR Or, someone else could work on it(Tbh, I think whoever worked on implementing NEW_CHATROOM_UNREAD_POSITION related logic in ChatMain.vue in the first place is the best person to take this issue).

@SebinSong SebinSong closed this Feb 10, 2025
@SebinSong SebinSong deleted the sebin/task/#2548-chat-scrolling-bug branch February 12, 2025 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants