Files
ComfyUI_frontend/src
Godwin Iheuwa 7b274b74f1 fix: add beforeChange/afterChange to convertToSubgraph for proper undo (#7791)
## 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>
2026-01-11 00:11:08 -07:00
..
2026-01-06 19:45:36 -07:00
2026-01-06 19:10:40 +01:00
2024-09-25 16:01:50 +09:00
2025-12-10 11:08:47 -08:00