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

fix: message list freezes on selectChat #4638

Merged
merged 3 commits into from
Feb 14, 2025
Merged

Conversation

WofWca
Copy link
Collaborator

@WofWca WofWca commented Feb 13, 2025

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.

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 jumpToMessages (e.g. from gallery, from notification), and found no issues.

WofWca and others added 3 commits February 14, 2025 00:10
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]>
Copy link
Member

@nicodh nicodh left a 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 WofWca merged commit 6be463d into main Feb 14, 2025
12 checks passed
@WofWca WofWca deleted the wofwca/fix-message-list-freezes branch February 14, 2025 14:19
@ralphtheninja
Copy link
Member

ralphtheninja commented Feb 15, 2025

@WofWca I'm seeing errors in the log when deleting a chat:

image

After some digging (debugger statement in getLastKnownScrollPosition() when document.querySelector('#message-list') returns null) this is triggered in messagelist.tsx in the refresh-reducer. See callstack below:

image

image

image

image

image

@WofWca
Copy link
Collaborator Author

WofWca commented Feb 16, 2025

@ralphtheninja This seems like a different issue.

@ralphtheninja
Copy link
Member

@ralphtheninja This seems like a different issue.

Yes, maybe. But it's called from messagelist.ts and thought you maybe had an idea.

@WofWca
Copy link
Collaborator Author

WofWca commented Feb 16, 2025

Not off the top of my head. Maybe this code is executed on the old instance of messagelist.ts.

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.

4 participants