mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-01 05:49:54 +00:00
## Summary - Adds missing `beforeChange()` and `afterChange()` lifecycle calls to `convertToSubgraph()` method ## Problem When converting nodes to a subgraph and then pressing Ctrl+Z to undo, the node positions were being changed from their original locations instead of being properly restored. ## Root Cause The `convertToSubgraph()` method in `LGraph.ts` was missing the `beforeChange()` and `afterChange()` lifecycle calls that are needed for proper undo/redo state tracking. These calls record the graph state before and after modifications. The inverse operation `unpackSubgraph()` already has these calls (see line 1742), so this is simply matching the existing pattern. ## Solution Add `beforeChange()` at the start of the method (after validation) and `afterChange()` before the return. ## Testing 1. Create a workflow with several nodes positioned in specific locations 2. Select 2-3 nodes 3. Right-click → "Convert Selection to Subgraph" 4. Press Ctrl+Z to undo 5. Verify nodes return to their exact original positions Fixes comfyanonymous/ComfyUI#11514 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7791-fix-add-beforeChange-afterChange-to-convertToSubgraph-for-proper-undo-2d86d73d36508125a2c4e4a412cced4a) by [Unito](https://www.unito.io) --------- Co-authored-by: RUiNtheExtinct <deepkarma001@gmail.com>