fix: invalidate currentChatRef before await in handleNewChat and handleResumeNew
The previous fix (990f044) moved state clears before the createChatSession
await but left currentChatRef.current pointing at the old session during the
entire network call. Any in-flight handleSend/handleTaskSubmit for the old
session would pass the guard (oldId === oldId) and re-apply stale task lane
data to the new empty session.
Setting currentChatRef.current = null before the await ensures in-flight
handlers from the previous session see a mismatch and bail — matching the
same pattern already used correctly in selectChat.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,10 @@ export default function AssistantChatPage() {
|
||||
}, [])
|
||||
|
||||
const handleNewChat = async () => {
|
||||
// Invalidate currentChatRef BEFORE the await so any in-flight handleSend/handleTaskSubmit
|
||||
// for the previous session sees a mismatch and bails — prevents stale task lane appearing
|
||||
// in the new empty session (same pattern as selectChat, which sets ref before its await).
|
||||
currentChatRef.current = null
|
||||
// Clear stale state immediately — don't wait for API to return
|
||||
setShowTaskLane(false)
|
||||
setActiveQuestions([])
|
||||
@@ -436,6 +440,8 @@ export default function AssistantChatPage() {
|
||||
}
|
||||
|
||||
const handleResumeNew = async (summary: string) => {
|
||||
// Invalidate currentChatRef BEFORE the await — same guard as handleNewChat
|
||||
currentChatRef.current = null
|
||||
// Clear stale state immediately — don't wait for API to return
|
||||
setShowTaskLane(false)
|
||||
setActiveQuestions([])
|
||||
|
||||
Reference in New Issue
Block a user