fix: prevent stale selectChat async results from clobbering new session task lane
Race condition: on page remount, selectChat(oldId) loads session data async. If the user clicks New Chat before the API returns, the old session's pending_task_lane was being applied to the new session's state, showing stale tasks and blocking new ones from appearing. Fix: currentChatRef tracks the most recently requested chat ID synchronously. All chat-creation paths (selectChat, handleNewChat, handleResumeNew) update it immediately. After each await in selectChat, bail if the ref no longer matches. Also documents the pattern as Lesson 106 in CLAUDE.md for future reference. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -373,7 +373,7 @@ gh run view <id> --json jobs --jq '.jobs[] | {name: .name, conclusion: .conclusi
|
||||
|
||||
**105. `npm run build` fails with `EACCES: permission denied` on `dist/` in code-server:** This is a filesystem permission issue in the Docker environment, not a TypeScript error — the TS compilation completes successfully. Use `npx tsc -b` to verify TypeScript cleanly without needing to write to `dist/`.
|
||||
|
||||
---
|
||||
**106. Guard async "select item → load data → apply state" flows with a ref:** When a component lets the user switch between items (chat sessions, flows, scripts) and loads data asynchronously on each switch, the load for item A can complete *after* the user has already switched to item B — overwriting B's state with A's stale data. Fix pattern: keep a `currentSelectionRef = useRef(initialId)` and update it synchronously whenever the selection changes (in every creation/switch path). After every `await`, bail out if `currentSelectionRef.current !== thisItemId`. See `AssistantChatPage.tsx` `selectChat` for the reference implementation (`currentChatRef`).
|
||||
|
||||
## RBAC & Permissions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user