-
Notifications
You must be signed in to change notification settings - Fork 456
fix: add beforeChange/afterChange to convertToSubgraph for proper undo #7791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: add beforeChange/afterChange to convertToSubgraph for proper undo #7791
Conversation
When converting nodes to a subgraph and then pressing Ctrl+Z to undo, the node positions were being changed from their original locations. This was because convertToSubgraph() was missing the beforeChange() and afterChange() lifecycle calls that are needed for proper undo/redo state tracking. The inverse operation unpackSubgraph() already had these calls. Fixes comfyanonymous/ComfyUI#11514
Ensure afterChange() is always called even if an exception occurs during subgraph conversion. This prevents undo/redo inconsistency when errors occur at lines 1535 or 1618. Extract mutation logic to private _convertToSubgraphImpl() method and wrap in try-finally to guarantee proper state tracking.
…ency Apply the same try-finally pattern to unpackSubgraph that was added to convertToSubgraph. This ensures afterChange() is always called even if an exception occurs during unpacking, preventing undo/redo inconsistency. Extract implementation to private _unpackSubgraphImpl() method following the same pattern as _convertToSubgraphImpl().
📝 WalkthroughWalkthroughAdds undo-friendly wrapping to subgraph conversion and unpacking operations in LGraph.ts by introducing private implementation methods and wrapping them with Changes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (9)src/**/*.{vue,ts}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
src/**/*.ts📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
src/**/*.{ts,tsx,vue}📄 CodeRabbit inference engine (src/CLAUDE.md)
Files:
src/**/*.{vue,ts,tsx}📄 CodeRabbit inference engine (src/CLAUDE.md)
Files:
src/lib/litegraph/**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (src/lib/litegraph/CLAUDE.md)
Files:
src/lib/litegraph/**/*.{ts,tsx}📄 CodeRabbit inference engine (src/lib/litegraph/CLAUDE.md)
Files:
**/*.{ts,tsx,vue}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,vue,js,jsx,json,css}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (9)📓 Common learnings📚 Learning: 2025-11-24T19:47:56.371ZApplied to files:
📚 Learning: 2025-11-24T19:47:56.371ZApplied to files:
📚 Learning: 2025-11-24T19:47:56.371ZApplied to files:
📚 Learning: 2025-11-24T19:47:56.371ZApplied to files:
📚 Learning: 2025-12-09T03:39:54.501ZApplied to files:
📚 Learning: 2025-12-13T11:03:11.264ZApplied to files:
📚 Learning: 2025-12-17T00:40:09.635ZApplied to files:
📚 Learning: 2025-12-11T12:25:15.470ZApplied to files:
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|

Summary
beforeChange()andafterChange()lifecycle calls toconvertToSubgraph()methodProblem
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 inLGraph.tswas missing thebeforeChange()andafterChange()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) andafterChange()before the return.Testing
Fixes comfyanonymous/ComfyUI#11514
┆Issue is synchronized with this Notion page by Unito