-
Notifications
You must be signed in to change notification settings - Fork 509
Prevent loading old messages twice on scroll #5198
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
Prevent loading old messages twice on scroll #5198
Conversation
Whenever the old messages are already loading initially when opening a conversation, a scroll event might call getOldMessages again which would cancel the previous one. The initial old messages load is using includeLastKnown=1 while the others use 0. So if it gets cancelled, we will miss the "last known" message as it won't be included in subsequent calls. This fix prevents repeated calls to getOldMessages to avoid the above issue. Signed-off-by: Vincent Petry <[email protected]>
|
Ay that's what I'm always experiencing |
| // Make the request | ||
| try { | ||
| const messages = await request({ token, lastKnownMessageId, includeLastKnown: includeLastKnown ? '1' : '0' }) | ||
| this.oldMessagesPromise = request({ token, lastKnownMessageId, includeLastKnown: includeLastKnown ? '1' : '0' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the component is reused, so you need to store this based on token?
Otherwise if you quickly change to 2 unloaded conversations the second one wouldn't load?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or more simply reset the value to null when the token changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you switch to another conversation the call will get cancelled anyway, so you'll then get a new request
nickvergessen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, seems to work
|
Queuing backport for after 11.0.0 is out |
|
/backport to stable21.1 |
Whenever the old messages are already loading initially when opening a
conversation, a scroll event might call getOldMessages again which would
cancel the previous one.
The initial old messages load is using includeLastKnown=1 while the others use
0. So if it gets cancelled, we will miss the "last known" message as it
won't be included in subsequent calls.
This fix prevents repeated calls to getOldMessages to avoid the above
issue.
See #3825 (comment) for semi-reliable reproduction steps and #3825 (comment) for some information.
The handleScroll method was sometimes calling getOldMessages(false) while we still had getOldMessages(true), which led to having a missing message in the list. Usually the one with the read marker, hence why I discovered it only in the PR above.
With a bit of luck this might also fix #5188 as it will also prevent repeated calls to getOldMessages(false) if scrolling up/down multiple times when at the top of the container.