fix(web): restore the last active chat session#1385
Conversation
| })) | ||
| }, []) | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
The hydration effect is not safe under React StrictMode. In development, React runs the effect setup/cleanup/setup sequence on initial mount. The first pass sets the hydratedInitialSessionRef flag and starts the restore request, the cleanup marks it cancelled, and the second pass exits early because the flag is already set. That means the restored messages never get applied, so the feature appears broken locally.
There was a problem hiding this comment.
Adjusted in 16ce1a8. I removed the one-shot hydration gate so the initial restore effect remains safe under React StrictMode, and the restore now only applies if the session and local message revision are still unchanged when the request resolves.
| content: m.content, | ||
| timestamp: fallbackTime, | ||
| })) | ||
| const historyMessages = await loadSessionMessages(sessionId) |
There was a problem hiding this comment.
The initial restore request is not guarded against later state changes. While loadSessionMessages(storedSessionId) is in flight, the websocket can already reconnect and receive new messages, or the user can switch to another session. When the restore promise resolves, it unconditionally calls setMessages(historyMessages), which can overwrite newer live messages or leave messages out of sync with activeSessionId.
There was a problem hiding this comment.
Adjusted in 16ce1a8. The initial restore path now captures a message revision before requesting history and skips applying the result if the user switched sessions or any newer messages landed while the request was in flight, so it no longer overwrites live state.
…ast-session fix(web): restore the last active chat session
…ast-session fix(web): restore the last active chat session
…ast-session fix(web): restore the last active chat session
…ast-session fix(web): restore the last active chat session
Fixes #1373.
Summary
Testing