From 52d9f3162199bbf7adbb73a8141bd1ad4bcf7e2d Mon Sep 17 00:00:00 2001 From: waleed Date: Sat, 31 Jan 2026 21:01:55 -0800 Subject: [PATCH] fix(undo-redo): use consistent target state for toggle redo The redo logic for BATCH_TOGGLE_ENABLED and BATCH_TOGGLE_LOCKED was incorrectly computing each block's new state as !previousStates[blockId]. However, the store's batchToggleEnabled/batchToggleLocked set ALL blocks to the SAME target state based on the first block's previous state. Now redo computes targetState = !previousStates[firstBlockId] and applies it to all blocks, matching the store's behavior. Co-Authored-By: Claude Opus 4.5 --- apps/sim/hooks/use-undo-redo.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/sim/hooks/use-undo-redo.ts b/apps/sim/hooks/use-undo-redo.ts index 75c72e399..252f0785a 100644 --- a/apps/sim/hooks/use-undo-redo.ts +++ b/apps/sim/hooks/use-undo-redo.ts @@ -1447,10 +1447,12 @@ export function useUndoRedo() { userId, }) - // Use setBlockEnabled to directly set to toggled state - // Redo sets to !previousStates (the state after the original toggle) + // Compute target state the same way batchToggleEnabled does: + // use !firstBlock.enabled, where firstBlock is blockIds[0] + const firstBlockId = blockIds[0] + const targetEnabled = !previousStates[firstBlockId] validBlockIds.forEach((blockId) => { - useWorkflowStore.getState().setBlockEnabled(blockId, !previousStates[blockId]) + useWorkflowStore.getState().setBlockEnabled(blockId, targetEnabled) }) break } @@ -1505,10 +1507,12 @@ export function useUndoRedo() { userId, }) - // Use setBlockLocked to directly set to toggled state - // Redo sets to !previousStates (the state after the original toggle) + // Compute target state the same way batchToggleLocked does: + // use !firstBlock.locked, where firstBlock is blockIds[0] + const firstBlockId = blockIds[0] + const targetLocked = !previousStates[firstBlockId] validBlockIds.forEach((blockId) => { - useWorkflowStore.getState().setBlockLocked(blockId, !previousStates[blockId]) + useWorkflowStore.getState().setBlockLocked(blockId, targetLocked) }) break }