Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: merge subblock values in auto-layout to prevent losing router co…
…ntext

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>
  • Loading branch information
waleedlatif1 and claude committed Apr 8, 2026
commit aac05b608eaf1a13b0bd9a3a3023d87f4a52df98
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DEFAULT_LAYOUT_PADDING,
DEFAULT_VERTICAL_SPACING,
} from '@/lib/workflows/autolayout/constants'
import { mergeSubblockState } from '@/stores/workflows/utils'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'

const logger = createLogger('AutoLayoutUtils')
Expand Down Expand Up @@ -109,10 +110,12 @@ export async function applyAutoLayoutAndUpdateStore(
return { success: false, error: errorMessage }
}

// Update workflow store immediately with new positions
const layoutedBlocks = result.data?.layoutedBlocks || blocks
const mergedBlocks = mergeSubblockState(layoutedBlocks, workflowId)

const newWorkflowState = {
...workflowStore.getWorkflowState(),
blocks: result.data?.layoutedBlocks || blocks,
blocks: mergedBlocks,
lastSaved: Date.now(),
}

Expand Down Expand Up @@ -167,9 +170,10 @@ export async function applyAutoLayoutAndUpdateStore(
})

// Revert the store changes since database save failed
const revertBlocks = mergeSubblockState(blocks, workflowId)
useWorkflowStore.getState().replaceWorkflowState({
...workflowStore.getWorkflowState(),
blocks,
blocks: revertBlocks,
lastSaved: workflowStore.lastSaved,
})

Expand Down
Loading