Skip to content

Commit 75a3e2c

Browse files
authored
fix(workspace): prevent stale placeholder data from corrupting workflow registry on switch
1 parent cdd0f75 commit 75a3e2c

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

apps/sim/hooks/queries/workflows.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,36 @@ export function useWorkflows(
113113
})
114114

115115
useEffect(() => {
116-
if (syncRegistry && scope === 'active' && workspaceId && query.status === 'pending') {
116+
if (
117+
syncRegistry &&
118+
scope === 'active' &&
119+
workspaceId &&
120+
(query.status === 'pending' || query.isPlaceholderData)
121+
) {
117122
beginMetadataLoad(workspaceId)
118123
}
119-
}, [syncRegistry, scope, workspaceId, query.status, beginMetadataLoad])
124+
}, [syncRegistry, scope, workspaceId, query.status, query.isPlaceholderData, beginMetadataLoad])
120125

121126
useEffect(() => {
122127
if (
123128
syncRegistry &&
124129
scope === 'active' &&
125130
workspaceId &&
126131
query.status === 'success' &&
127-
query.data
132+
query.data &&
133+
!query.isPlaceholderData
128134
) {
129135
completeMetadataLoad(workspaceId, query.data)
130136
}
131-
}, [syncRegistry, scope, workspaceId, query.status, query.data, completeMetadataLoad])
137+
}, [
138+
syncRegistry,
139+
scope,
140+
workspaceId,
141+
query.status,
142+
query.data,
143+
query.isPlaceholderData,
144+
completeMetadataLoad,
145+
])
132146

133147
useEffect(() => {
134148
if (syncRegistry && scope === 'active' && workspaceId && query.status === 'error') {

apps/sim/hooks/queries/workspace.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,9 @@ export function useCreateWorkspace() {
8686
const data = await response.json()
8787
return data.workspace as Workspace
8888
},
89-
onSuccess: (data) => {
90-
queryClient.invalidateQueries({ queryKey: workspaceKeys.all })
91-
if (data?.id) {
92-
queryClient.removeQueries({ queryKey: workspaceKeys.detail(data.id) })
93-
queryClient.removeQueries({ queryKey: workspaceKeys.settings(data.id) })
94-
queryClient.removeQueries({ queryKey: workspaceKeys.permissions(data.id) })
95-
queryClient.removeQueries({ queryKey: workspaceKeys.members(data.id) })
96-
}
89+
onSuccess: () => {
90+
queryClient.invalidateQueries({ queryKey: workspaceKeys.lists() })
91+
queryClient.invalidateQueries({ queryKey: workspaceKeys.adminLists() })
9792
},
9893
})
9994
}

apps/sim/lib/copilot/client-sse/handlers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { STREAM_STORAGE_KEY } from '@/lib/copilot/constants'
33
import { asRecord } from '@/lib/copilot/orchestrator/sse/utils'
44
import type { SSEEvent } from '@/lib/copilot/orchestrator/types'
55
import {
6+
abortAllInProgressTools,
67
isBackgroundState,
78
isRejectedState,
89
isReviewState,
@@ -956,7 +957,7 @@ export const sseHandlers: Record<string, SSEHandler> = {
956957
}))
957958
context.streamComplete = true
958959
},
959-
stream_end: (_data, context, _get, set) => {
960+
stream_end: (_data, context, get, set) => {
960961
if (context.pendingContent) {
961962
if (context.isInThinkingBlock && context.currentThinkingBlock) {
962963
appendThinkingContent(context, context.pendingContent)
@@ -967,6 +968,7 @@ export const sseHandlers: Record<string, SSEHandler> = {
967968
}
968969
finalizeThinkingBlock(context)
969970
updateStreamingMessage(set, context)
971+
abortAllInProgressTools(set, get)
970972
},
971973
default: () => {},
972974
}

0 commit comments

Comments
 (0)