Overview
Subgraphs let users group nodes into reusable, nestable components. Each subgraph is its ownLGraph with a UUID. For the user-facing guide, see Subgraphs.
Node Identifiers
ComfyUI uses three distinct node identifier types. Using the wrong one causes silent failures.
To construct a node’s locator ID from within an extension:
Traversing Nodes
Current layer only
All nodes recursively
To walk into nested subgraphs, use a recursive helper that calls a callback on every node:Root vs Active Graph
Events
Subgraph-level events
Dispatched onsubgraph.events:
Canvas-level events
Dispatched onapp.canvas.canvas (the HTML canvas element):
Listening pattern
Widget Promotion
When aSubgraphInput connects to a widget inside a subgraph, a copy of that widget appears on the parent subgraph node. This fires widget-promoted. Removing the connection fires widget-demoted.
Cleanup
Use anAbortController to clean up all event listeners when a node is removed.