Skip to content

Commit 84cc5bd

Browse files
committed
fix(undo-redo): preserve subblock values during undo/redo cycles
1 parent 408597e commit 84cc5bd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

apps/sim/hooks/use-undo-redo.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ export function useUndoRedo() {
473473
}
474474
})
475475
batchRemoveOp.data.subBlockValues = latestSubBlockValues
476+
;(entry.operation as BatchAddBlocksOperation).data.subBlockValues = latestSubBlockValues
476477

477478
addToQueue({
478479
id: opId,
@@ -1153,6 +1154,36 @@ export function useUndoRedo() {
11531154
break
11541155
}
11551156

1157+
const latestEdges = useWorkflowStore
1158+
.getState()
1159+
.edges.filter(
1160+
(e) => existingBlockIds.includes(e.source) || existingBlockIds.includes(e.target)
1161+
)
1162+
batchOp.data.edgeSnapshots = latestEdges
1163+
1164+
const latestSubBlockValues: Record<string, Record<string, unknown>> = {}
1165+
existingBlockIds.forEach((blockId) => {
1166+
const merged = mergeSubblockState(
1167+
useWorkflowStore.getState().blocks,
1168+
activeWorkflowId,
1169+
blockId
1170+
)
1171+
const block = merged[blockId]
1172+
if (block?.subBlocks) {
1173+
const values: Record<string, unknown> = {}
1174+
Object.entries(block.subBlocks).forEach(([subBlockId, subBlock]) => {
1175+
if (subBlock.value !== null && subBlock.value !== undefined) {
1176+
values[subBlockId] = subBlock.value
1177+
}
1178+
})
1179+
if (Object.keys(values).length > 0) {
1180+
latestSubBlockValues[blockId] = values
1181+
}
1182+
}
1183+
})
1184+
batchOp.data.subBlockValues = latestSubBlockValues
1185+
;(entry.inverse as BatchAddBlocksOperation).data.subBlockValues = latestSubBlockValues
1186+
11561187
addToQueue({
11571188
id: opId,
11581189
operation: {

0 commit comments

Comments
 (0)