diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index 19b32b630..ac0a9b8ed 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -3608,6 +3608,7 @@ export class LGraphCanvas subgraphs: [] } + // NOTE: logic for traversing nested subgraphs depends on this being a set. const subgraphs = new Set() // Create serialisable objects @@ -3646,8 +3647,13 @@ export class LGraphCanvas } // Add unique subgraph entries - // TODO: Must find all nested subgraphs + // NOTE: subgraphs is appended to mid iteration. for (const subgraph of subgraphs) { + for (const node of subgraph.nodes) { + if (node instanceof SubgraphNode) { + subgraphs.add(node.subgraph) + } + } const cloned = subgraph.clone(true).asSerialisable() serialisable.subgraphs.push(cloned) } @@ -3764,12 +3770,19 @@ export class LGraphCanvas created.push(group) } + // Update subgraph ids with nesting + function updateSubgraphIds(nodes: { type: string }[]) { + for (const info of nodes) { + const subgraph = results.subgraphs.get(info.type) + if (!subgraph) continue + info.type = subgraph.id + updateSubgraphIds(subgraph.nodes) + } + } + updateSubgraphIds(parsed.nodes) + // Nodes for (const info of parsed.nodes) { - // If the subgraph was cloned, update references to use the new subgraph ID. - const subgraph = results.subgraphs.get(info.type) - if (subgraph) info.type = subgraph.id - const node = info.type == null ? null : LiteGraph.createNode(info.type) if (!node) { // failedNodes.push(info)