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); },