-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
fix: message list freezes on selectChat #4638
Conversation
FYI this moves the jumpToMessage function without changing it. This should fix the bug where we'd try to load too many messages, namely (almost) all messages of the chat. The problem is that `loadChat` might return early, to delegate its job to `effect.jumpToMessage`, but there could already be other effects (such as `fetchMoreMessagesTop`) already queued up, so the `effect.jumpToMessage` would get added to the back of the queue, resulting in other operations getting executed prior to the `jumpToMessage`. Those other operations do not work well with an uninitialized store state, namely when `oldestFetchedMessageListItemIndex` is `-1`. In particular, `fetchMoreMessagesTop` would call `loadMessages` with `newestFetchedMessageListItemIndex === -2` and `oldestFetchedMessageListItemIndex === 0`, which, in turn, would call `getMessages()` with the list of almost all message IDs. Reproduction steps (not 100% reliable): 1. Open chat 1. 2. Receive a message in chat 2. Use a different device to send the message. It is preferable to keep the window focused. 3. Wait ~5 seconds (not sure why). 4. Click on chat 2 in the chat list. Chat 2 will open, but with a much greater delay. This commit also has potential to fix the issue where the messages list does not show any messages when the chat gets opened. And maybe other problems might get fixed, because this fixes a race condition. The problem has likely been surfaced by the recent "performance" changes and bug fixes related to messagelist.ts. Users report that it has become noticeable on 1.53.0, see diff: v1.52.1...v1.53.0 Co-Authored-By: ralphtheninja <[email protected]> Co-authored-by: Nico de Haen <[email protected]>
a58cee7
to
89af4c3
Compare
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.
Reiewed by testing
@WofWca I'm seeing errors in the log when deleting a chat: After some digging ( |
@ralphtheninja This seems like a different issue. |
Yes, maybe. But it's called from |
Not off the top of my head. Maybe this code is executed on the old instance of |
FYI this moves the jumpToMessage function without changing it.
This should fix the bug where we'd try to load too many messages,
namely (almost) all messages of the chat.
The problem is that
loadChat
might return early,to delegate its job to
effect.jumpToMessage
,but there could already be other effects
(such as
fetchMoreMessagesTop
) already queued up,so the
effect.jumpToMessage
would get addedto the back of the queue, resulting in other operations getting
executed prior to the
jumpToMessage
.Those other operations do not work well with an uninitialized
store state, namely when
oldestFetchedMessageListItemIndex
is-1
.In particular,
fetchMoreMessagesTop
would callloadMessages
with
newestFetchedMessageListItemIndex === -2
andoldestFetchedMessageListItemIndex === 0
, which, in turn,would call
getMessages()
with the list of almost all message IDs.Reproduction steps (not 100% reliable):
Use a different device to send the message.
It is preferable to keep the window focused.
Chat 2 will open, but with a much greater delay.
2025-02-14-GuZP878AWW.mp4
This commit also has potential to fix the issue
where the messages list does not show any messages
when the chat gets opened.
And maybe other problems might get fixed, because this fixes
a race condition.
The problem has likely been surfaced by the recent "performance"
changes and bug fixes related to messagelist.ts.
Users report that it has become noticeable on 1.53.0, see diff:
v1.52.1...v1.53.0
I tested this for ~15 minutes with various other
jumpToMessage
s (e.g. from gallery, from notification), and found no issues.