Skip to content

Commit 0b31cce

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 0b31cce

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 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,16 @@ export async function applyAutoLayoutAndUpdateStore(
109111
return { success: false, error: errorMessage }
110112
}
111113

114+
// Merge subblock values from the subblock store into the layouted blocks
115+
// to ensure runtime-edited values (e.g. router context) are preserved
116+
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
117+
const layoutedBlocks = result.data?.layoutedBlocks || blocks
118+
const mergedBlocks = mergeSubblockState(layoutedBlocks, activeWorkflowId ?? undefined)
119+
112120
// Update workflow store immediately with new positions
113121
const newWorkflowState = {
114122
...workflowStore.getWorkflowState(),
115-
blocks: result.data?.layoutedBlocks || blocks,
123+
blocks: mergedBlocks,
116124
lastSaved: Date.now(),
117125
}
118126

@@ -167,9 +175,10 @@ export async function applyAutoLayoutAndUpdateStore(
167175
})
168176

169177
// Revert the store changes since database save failed
178+
const revertBlocks = mergeSubblockState(blocks, activeWorkflowId ?? undefined)
170179
useWorkflowStore.getState().replaceWorkflowState({
171180
...workflowStore.getWorkflowState(),
172-
blocks,
181+
blocks: revertBlocks,
173182
lastSaved: workflowStore.lastSaved,
174183
})
175184

0 commit comments

Comments
 (0)