Skip to content

Commit 2a64808

Browse files
trim comments
1 parent 77c3cf8 commit 2a64808

2 files changed

Lines changed: 3 additions & 21 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

apps/sim/hooks/queries/copilot-chat-selection.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ export const copilotChatSelectionKeys = {
99
}
1010

1111
/**
12-
* Reactive per-workflow copilot chat selection. The active workflow's
13-
* chatId lives in the React Query cache under a workflow-keyed entry, so
14-
* switching workflows naturally reads the per-workflow remembered value
15-
* with no save/restore effect required. No `queryFn` runs — values land
16-
* exclusively via the returned setter.
17-
*
18-
* In-memory only (no `persistQueryClient`); refresh wipes the memory and
19-
* the panel falls back to auto-selecting the workflow's most recent chat.
12+
* Reactive per-workflow copilot chat selection. Values are written via the
13+
* returned setter; the queryFn is never invoked.
2014
*/
2115
export function useCopilotChatSelection(workflowId?: string) {
2216
const queryClient = useQueryClient()

0 commit comments

Comments
 (0)