Fix duplicated inputs on loading nested subgraphs

Subgraphs are loaded in order of creation. Under most circumstances,
this means newer subgraphs are loaded first. With nested subgraphs, this
means a subgraph node has it's inputs connected before it's inside is
loaded. When the inner subgraph is loaded, input-added events are
triggered even though inputs already exist on the subgraph node.

This is resolved by adding a check for if an input of the corresponding
name already exists when adding an input.

Port of https://github.com/Comfy-Org/litegraph.js/pull/1192
This commit is contained in:
Benjamin Lu
2025-08-05 18:28:07 -04:00
parent fad8dae796
commit 01e4260d4c

View File

@@ -72,6 +72,7 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
(e) => {
const subgraphInput = e.detail.input
const { name, type } = subgraphInput
if (this.inputs.some((i) => i.name == name)) return
const input = this.addInput(name, type)
this.#addSubgraphInputListeners(subgraphInput, input)