fix: prevent task lane from showing previous session's data on switch
Root cause: race condition between setActiveChatId and the persist
effect. When switching from session A to B, setActiveChatId(B) triggers
the persist effect which writes {chatId: B, questions: [A's data]} to
sessionStorage BEFORE the async selectChat clears the task lane. The
sessionStorage fallback then finds chatId === B and restores A's stale
task lane data.
Fix: clear task lane state synchronously in selectChat before the await.
Server-side pending_task_lane restores it if the new session has data.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -169,7 +169,12 @@ export function useAssistantSession() {
|
||||
const selectChat = useCallback(async (chatId: string) => {
|
||||
currentChatRef.current = chatId
|
||||
setActiveChatId(chatId)
|
||||
// Don't clear task lane yet — wait for server response to decide
|
||||
// Clear task lane immediately to prevent the persist effect from
|
||||
// tagging the old session's data with the new chatId (race condition).
|
||||
// Server-side pending_task_lane will restore it below if it exists.
|
||||
setActiveQuestions([])
|
||||
setActiveActions([])
|
||||
setShowTaskLane(false)
|
||||
try {
|
||||
const detail = await aiSessionsApi.getSession(chatId)
|
||||
if (currentChatRef.current !== chatId) return
|
||||
|
||||
Reference in New Issue
Block a user