Skip to content

Commit 84150c2

Browse files
committed
fix(workspace): prevent stale placeholder data from corrupting workflow registry on switch
- Guard completeMetadataLoad to skip when isPlaceholderData is true, preventing the previous workspace's workflows from briefly populating the registry during switch - Trigger beginMetadataLoad when isPlaceholderData is true to ensure loading state is shown correctly on direct URL navigation (no switchToWorkspace call) - Narrow useCreateWorkspace invalidation from workspaceKeys.all to workspaceKeys.lists() to avoid unnecessary refetches of permissions, settings, and members
1 parent 95b17ff commit 84150c2

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
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: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,8 @@ 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() })
9791
},
9892
})
9993
}

0 commit comments

Comments
 (0)