Skip to content

Conversation

@krishna9358
Copy link
Contributor

Summary

  • Fix undo/redo not restoring edge connections properly
  • Fix keyboard delete not capturing history snapshots
  • Ensure consistent snapshot capture with both nodes and edges

Issues

  1. Connections not restoring on undo
    When undoing changes, nodes would restore but edge connections would not. This made undo/redo appear broken for connection-related operations.
  2. Keyboard delete bypassing history
    Deleting nodes or edges via keyboard (Delete/Backspace) directly modified state without capturing a snapshot, so these deletions couldn't be undone.
  3. Inconsistent snapshot capture
    Edge changes were being captured with captureSnapshot(undefined, nextEdges) which relied on potentially stale ref values for nodes, leading to inconsistent history states.

Root Causes

  • Missing snapshot for keyboard delete: The keyboard event handler in Canvas.tsx called setNodes/setEdges directly without calling onSnapshot. This meant deletions via keyboard were never recorded in history.
  • Edge-only snapshots: When edges were changed, onEdgesChange in WorkflowBuilder.tsx was only passing the new edges to captureSnapshot(undefined, nextEdges). Since refs are updated asynchronously via useEffect, the nodes ref could be stale, causing the snapshot to have inconsistent node/edge state.
  • Debounce merging issues: The 50ms debounce in captureSnapshot could merge snapshots incorrectly when changes came from different sources (e.g., node deletion triggering both onNodesChange and onEdgesChange).

Fix

  • Canvas.tsx keyboard handler: Added snapshot capture for Delete/Backspace operations. Now calculates the next state (nodes and edges) before applying changes, then captures a consistent snapshot.
  • WorkflowBuilder.tsx onEdgesChange: Changed from captureSnapshot(undefined, nextEdges) to captureSnapshot(currentNodes, nextEdges) to always pass both nodes and edges for a consistent snapshot.
  • useWorkflowHistory.ts: Updated documentation to emphasize the importance of always passing both nodes and edges for consistent snapshots.

Testing

  • bun run test
  • bun run lint
  • bun run typecheck
  • Additional notes:

Documentation

  • Updated the relevant doc(s) (see docs/guide.md) or checked that no updates are needed.
  • Recorded contract/architecture changes in both public docs and .ai logs when applicable.

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@LuD1161 LuD1161 merged commit 02b888e into main Feb 1, 2026
3 checks passed
@LuD1161 LuD1161 deleted the @krishna9358/undo-redo branch February 1, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants