diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index d87e49658..dc47f477e 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -313,9 +313,8 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { widget: Readonly ) { // Use the first matching widget - const promotedWidget = toConcreteWidget(widget, this).createCopyForNode( - this - ) + const targetWidget = toConcreteWidget(widget, this) + const promotedWidget = targetWidget.createCopyForNode(this) Object.assign(promotedWidget, { get name() { @@ -370,7 +369,15 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { subgraphNode: this }) - input.widget = { name: subgraphInput.name } + // NOTE: This code creates linked chains of prototypes for passing across + // multiple levels of subgraphs. As part of this, it intentionally avoids + // creating new objects. Have care when making changes. + const backingInput = + targetWidget.node.findInputSlot(widget.name, true)?.widget ?? {} + input.widget ??= { name: subgraphInput.name } + input.widget.name = subgraphInput.name + Object.setPrototypeOf(input.widget, backingInput) + input._widget = promotedWidget }