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: chat list & chat view desync, again #4628

Merged
merged 1 commit into from
Feb 13, 2025
Merged

Conversation

WofWca
Copy link
Collaborator

@WofWca WofWca commented Feb 11, 2025

This is a follow-up to
#4501
(166ee8a).

The issue now is that cancelPendingSetChat.current = undefined
unsets the cancel function for a different selectChat() call.

This happens when you selectChat more than 2 times
in a quick succession. And can go like this:

  1. set cancelPendingSetChat for chat 1
  2. set cancelPendingSetChat for chat 2
  3. chat loaded 1
  4. unset cancelPendingSetChat, from chat 1
  5. set cancelPendingSetChat for chat 3
  6. chat loaded 3
  7. unset cancelPendingSetChat, from chat 3
  8. chat loaded 2
  9. unset cancelPendingSetChat, from chat 2

As you can see, when we called selectChat(2),
it set cancelPendingSetChat (entry 2), but chat 1 loaded first,
and it unset cancelPendingSetChat (entry 4).
So when we called selectChat(3) (entry 5), it thought that
there is nothing to cancel, so it didn't actually cancel
the loading of the previous chat 2.
Chat 2 loaded last, but its cancelled was false
so it replaced the state.
But it should not have happened, because selectChat(3)
was called last.

Basically, as you can see from the code,
this commit ensures that one selectChat cannot reset
cancelPendingSetChat.current if it belongs to a different
selectChat() call.

This is a follow-up to
#4501
(166ee8a).

The issue now is that `cancelPendingSetChat.current = undefined`
unsets the cancel function for a different `selectChat()` call.

This happens when you selectChat more than 2 times
in a quick succession. And can go like this:

1. set cancelPendingSetChat for chat 1
2. set cancelPendingSetChat for chat 2
3. chat loaded 1
4. unset cancelPendingSetChat, from chat 1
5. set cancelPendingSetChat for chat 3
6. chat loaded 3
7. unset cancelPendingSetChat, from chat 3
8. chat loaded 2
9. unset cancelPendingSetChat, from chat 2

As you can see, when we called `selectChat(2)`,
it set cancelPendingSetChat (entry 2), but chat 1 loaded first,
and it unset cancelPendingSetChat (entry 4).
So when we called `selectChat(3)` (entry 5), it thought that
there is nothing to cancel, so it didn't actually cancel
the loading of the previous chat 2.
Chat 2 loaded last, but its `cancelled` was `false`
so it replaced the state.
But it should not have happened, because `selectChat(3)`
was called last.

Basically, as you can see from the code,
this commit ensures that one `selectChat` cannot reset
`cancelPendingSetChat.current` if it belongs to a different
`selectChat()` call.
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.

Reviewed by reading

@WofWca WofWca merged commit 240716c into main Feb 13, 2025
11 of 12 checks passed
@WofWca WofWca deleted the wofwca/fix-selectChat-race-2 branch February 13, 2025 10:40
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