Browse Source

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 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 4 months ago
parent
commit
a1073dc070
  1. 13
      src/store/workflowStore.ts

13
src/store/workflowStore.ts

@ -1992,6 +1992,12 @@ const workflowStoreImpl: StateCreator<WorkflowStore> = (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<WorkflowStore> = (set, get) => ({
skippedNodeIds: new Set<string>(),
});
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);
},

Loading…
Cancel
Save