Skip to main content

Overview

Subgraphs let users group nodes into reusable, nestable components. Each subgraph is its own LGraph 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:
Full example:

Root vs Active Graph

Events

Subgraph-level events

Dispatched on subgraph.events:

Canvas-level events

Dispatched on app.canvas.canvas (the HTML canvas element):

Listening pattern

Widget Promotion

When a SubgraphInput 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.
Widget promotion behavior is still evolving and may change in future releases.

Cleanup

Use an AbortController to clean up all event listeners when a node is removed.
onRemoved can also fire during subgraph conversion, not just deletion. Guard teardown logic if you need to preserve state across restructuring.

See Also