Skip to content

Workflow redo does not apply an empty-graph snapshot (deleted last node reappears) #45442

Open

Description

@hyoban

Summary

Undo/redo skips history snapshots that contain an empty graph. If you delete the last node, undo, and then redo, the node stays on the canvas even though the history pointer has moved forward.

Where

web/app/components/workflow/hooks/use-nodes-interactions.ts (verified on main at fbc33cae43):

  • handleHistoryForward (~L2363-2375): calls redo(), then if (edges.length === 0 && nodes.length === 0) return before setEdges/setNodes.
  • handleHistoryBack (~L2341-2353) has the same guard after undo().

Steps to reproduce

  1. Create a workflow whose canvas has a single deletable node, for example only the Start node.
  2. Select the node and delete it. The canvas is now empty.
  3. Undo (Ctrl/Cmd+Z). The node comes back, as expected.
  4. Redo (Ctrl+Y / Cmd+Shift+Z).

Expected

The redo re-applies the delete and the canvas is empty again.

Actual

The history store moves forward to the empty snapshot, but the early return means the canvas is never updated, so the node is still shown. Canvas and history are now out of sync, and the next undo/redo steps operate on the wrong baseline. The same guard in handleHistoryBack probably prevents undoing back to an empty-graph snapshot as well.

Suggested fix

Remove the empty-graph early return, or use a distinct sentinel for "no snapshot" so that a real empty graph is still applied (including the collaboration broadcast).

How this was found

This came up during the web test cleanup (#44381), when web/app/components/workflow/shortcuts/__tests__/workflow-canvas.spec.tsx was rewritten to assert the live canvas after undo/redo instead of only the history store. The regression in that spec keeps an unrelated node on the canvas to avoid this case. A test for the empty-graph redo should be added together with the fix.

Activity

  1. dosubot commented on Nov 3, 2026

    @dosubot

    One detail for the regression test: history capture is debounced by 500 ms, so wait for the deletion snapshot to reach history before issuing undo. The existing canvas spec already does this by waiting for pastStates to have length 1. That avoids testing a pending history write instead of the empty-snapshot behavior. [1] [2]

    A complementary case would start empty, add a node, then undo back to empty. That exercises handleHistoryBack independently of the reported redo sequence, since both handlers contain the same guard. [3]

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about dify with Dosu

  2. added
    1.18.0
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.18.0project#dify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions