From 68845ce33a106778f75ff89c533897cb383d5e94 Mon Sep 17 00:00:00 2001 From: AustinMroz Date: Thu, 11 Sep 2025 14:27:44 -0700 Subject: [PATCH] Fix Connection of Primitive nodes to Subgraph node (#5024) * Fix connection of primitives to subgraphNodes * Fix loading and nested subgraphs with primitives Medium hackyness, but this saves ~100 lines. * Use improved type check * Remove requirement for type assertion * Add warning comment --------- Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com> --- src/lib/litegraph/src/subgraph/SubgraphNode.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 }