fixed a race condition in long-poll initialization by adding a token validation guard to prevent stale chat sessions from hijacking the current state during navigation or app resumes.
This commit is contained in:
@@ -196,6 +196,13 @@ class ChatBloc
|
||||
|
||||
void _startLongPoll(String token) {
|
||||
if (!_appResumed) return;
|
||||
// A load chain may finish AFTER the user already switched chats — e.g. a
|
||||
// notification tap resumes the app (lifecycle refresh starts loading the
|
||||
// still-open chat A) and then navigates to chat B. Without this guard the
|
||||
// stale chain's completion would hijack the long-poll back to A and its
|
||||
// responses would merge A's messages into B's state (chat B showing chat
|
||||
// A's content) while B never receives live updates.
|
||||
if ((innerState?.currentToken ?? '') != token) return;
|
||||
if (_pollingToken == token) return;
|
||||
_stopLongPoll();
|
||||
_pollingToken = token;
|
||||
|
||||
Reference in New Issue
Block a user