Skip to content

Commit 51492d8

Browse files
committed
fix(workflows): resolve cold-start deadlock on direct URL navigation
loadWorkflowState used hydration.workspaceId (null on cold start) to look up the RQ cache, causing "Workflow not found" even when the workflow exists in the DB. Now falls back to getWorkspaceIdFromUrl() and skips the cache guard when the cache is empty (letting the API fetch proceed). Also removes the redundant isRegistryReady guard in workflow.tsx that blocked setActiveWorkflow when hydration.workspaceId was null.
1 parent c73ee9e commit 51492d8

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,16 +2200,11 @@ const WorkflowContent = React.memo(
22002200
if (sandbox) return
22012201

22022202
const currentId = workflowIdParam
2203-
const currentWorkspaceHydration = hydration.workspaceId
2204-
2205-
const isRegistryReady = hydration.workspaceId !== null
2206-
2207-
// Wait for registry to be ready to prevent race conditions
2203+
// Wait for workflow data to be available before attempting to load
22082204
if (
22092205
!currentId ||
22102206
!currentWorkflowExists ||
2211-
!isRegistryReady ||
2212-
(currentWorkspaceHydration && currentWorkspaceHydration !== workspaceId)
2207+
(hydration.workspaceId && hydration.workspaceId !== workspaceId)
22132208
) {
22142209
return
22152210
}

apps/sim/stores/workflows/registry/store.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { create } from 'zustand'
33
import { devtools } from 'zustand/middleware'
44
import { DEFAULT_DUPLICATE_OFFSET } from '@/lib/workflows/autolayout/constants'
55
import { getQueryClient } from '@/app/_shell/providers/get-query-client'
6+
import { getWorkspaceIdFromUrl } from '@/hooks/queries/utils/get-workspace-id-from-url'
67
import { workflowKeys } from '@/hooks/queries/utils/workflow-keys'
78
import { useVariablesStore } from '@/stores/panel/variables/store'
89
import type {
@@ -142,15 +143,15 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
142143
},
143144

144145
loadWorkflowState: async (workflowId: string) => {
145-
// Check if the workflow exists in the React Query cache
146-
const workspaceId = get().hydration.workspaceId
146+
const workspaceId = get().hydration.workspaceId ?? getWorkspaceIdFromUrl()
147+
147148
const workflows = workspaceId
148149
? (getQueryClient().getQueryData<WorkflowMetadata[]>(
149150
workflowKeys.list(workspaceId, 'active')
150151
) ?? [])
151152
: []
152153

153-
if (!workflows.find((w) => w.id === workflowId)) {
154+
if (workflows.length > 0 && !workflows.find((w) => w.id === workflowId)) {
154155
const message = `Workflow not found: ${workflowId}`
155156
logger.error(message)
156157
set({ error: message })
@@ -163,7 +164,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
163164
error: null,
164165
hydration: {
165166
phase: 'state-loading',
166-
workspaceId: state.hydration.workspaceId,
167+
workspaceId: workspaceId ?? state.hydration.workspaceId,
167168
workflowId,
168169
requestId,
169170
error: null,

0 commit comments

Comments
 (0)