Skip to content

Commit c2765fa

Browse files
waleedlatif1claude
andcommitted
fix: merge subblock values in auto-layout to prevent losing router context
Auto-layout was reading from getWorkflowState() without merging subblock store values, then persisting stale subblock data to the database. This caused runtime-edited values (e.g. router_v2 context) to be overwritten with their initial/empty values whenever auto-layout was triggered. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4700590 commit c2765fa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
DEFAULT_LAYOUT_PADDING,
55
DEFAULT_VERTICAL_SPACING,
66
} from '@/lib/workflows/autolayout/constants'
7+
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
8+
import { mergeSubblockState } from '@/stores/workflows/utils'
79
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
810

911
const logger = createLogger('AutoLayoutUtils')
@@ -109,10 +111,13 @@ export async function applyAutoLayoutAndUpdateStore(
109111
return { success: false, error: errorMessage }
110112
}
111113

112-
// Update workflow store immediately with new positions
114+
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
115+
const layoutedBlocks = result.data?.layoutedBlocks || blocks
116+
const mergedBlocks = mergeSubblockState(layoutedBlocks, activeWorkflowId ?? undefined)
117+
113118
const newWorkflowState = {
114119
...workflowStore.getWorkflowState(),
115-
blocks: result.data?.layoutedBlocks || blocks,
120+
blocks: mergedBlocks,
116121
lastSaved: Date.now(),
117122
}
118123

@@ -167,9 +172,10 @@ export async function applyAutoLayoutAndUpdateStore(
167172
})
168173

169174
// Revert the store changes since database save failed
175+
const revertBlocks = mergeSubblockState(blocks, activeWorkflowId ?? undefined)
170176
useWorkflowStore.getState().replaceWorkflowState({
171177
...workflowStore.getWorkflowState(),
172-
blocks,
178+
blocks: revertBlocks,
173179
lastSaved: workflowStore.lastSaved,
174180
})
175181

0 commit comments

Comments
 (0)