From a1073dc07038c67927c8646a5875287fe9be89eb Mon Sep 17 00:00:00 2001 From: shrimbly Date: Tue, 31 Mar 2026 07:18:57 +1300 Subject: [PATCH] fix: clear pending undo debounce timer on loadWorkflow and clearWorkflow If a debounced data-edit snapshot was pending when loading or clearing a workflow, it could fire after undoManager.clear() and push stale state into the new workflow's undo history. Now both paths cancel the pending timer and snapshot before clearing. Co-Authored-By: Claude Opus 4.6 --- src/store/workflowStore.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/store/workflowStore.ts b/src/store/workflowStore.ts index 92df2075..188c30ad 100644 --- a/src/store/workflowStore.ts +++ b/src/store/workflowStore.ts @@ -1992,6 +1992,12 @@ const workflowStoreImpl: StateCreator = (set, get) => ({ } // Clear undo history — loading a workflow is a fresh start + // Cancel any pending debounced snapshot so it doesn't fire into the new workflow + pendingDataSnapshot = null; + if (dataChangeTimer) { + clearTimeout(dataChangeTimer); + dataChangeTimer = null; + } undoManager.clear(); syncUndoFlags(set); @@ -2025,7 +2031,12 @@ const workflowStoreImpl: StateCreator = (set, get) => ({ skippedNodeIds: new Set(), }); get().clearSnapshot(); - // Clear undo history + // Clear undo history and cancel any pending debounced snapshot + pendingDataSnapshot = null; + if (dataChangeTimer) { + clearTimeout(dataChangeTimer); + dataChangeTimer = null; + } undoManager.clear(); syncUndoFlags(set); },