@@ -223,10 +223,6 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
223223 const currentWorkflow = activeWorkflowId ? workflows [ activeWorkflowId ] : null
224224 const { isSnapshotView } = useCurrentWorkflow ( )
225225
226- // Per-workflow chat memory lives in the React Query cache, keyed by
227- // workflowId. Switching workflows reads the right cache entry on its own,
228- // so no save/restore effect is needed. Refresh wipes the cache and the
229- // panel falls back to auto-selecting most recent.
230226 const { chatId : copilotChatId , setChatId : setCopilotChatId } = useCopilotChatSelection (
231227 activeWorkflowId ?? undefined
232228 )
@@ -245,8 +241,6 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
245241 const copilotChatIdRef = useRef ( copilotChatId )
246242 copilotChatIdRef . current = copilotChatId
247243 const copilotInitialLoadDoneRef = useRef ( false )
248- // Tracks the live workflow so async chat-list fetches can detect
249- // workflow switches that happened mid-flight and bail out.
250244 const activeWorkflowIdRef = useRef ( activeWorkflowId )
251245 activeWorkflowIdRef . current = activeWorkflowId
252246
@@ -256,10 +250,7 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
256250 fetch ( '/api/copilot/chats' )
257251 . then ( ( res ) => ( res . ok ? res . json ( ) : { chats : [ ] } ) )
258252 . then ( ( data ) => {
259- // Stale-fetch guard: bail if the user switched workflows mid-flight.
260- // Without this the in-flight response would clobber the new
261- // workflow's state (filtering against the old workflow id, clearing
262- // the restored chat, and auto-selecting the wrong list's first chat).
253+ // Drop responses for a workflow we've already switched away from.
263254 if ( requestWorkflowId !== activeWorkflowIdRef . current ) return
264255 const allChats = Array . isArray ( data ?. chats ) ? data . chats : [ ]
265256 const filtered = allChats . filter (
@@ -275,9 +266,6 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
275266 const currentId = copilotChatIdRef . current
276267 let resolvedCurrentId = currentId
277268 if ( currentId && ! filtered . find ( ( c : { id : string } ) => c . id === currentId ) ) {
278- // Remembered chat was deleted (here or in another tab). Drop it
279- // so the next send doesn't hit a 404; setCopilotChatId(undefined)
280- // also clears the workflow's cached selection.
281269 setCopilotChatId ( undefined )
282270 resolvedCurrentId = undefined
283271 }
0 commit comments