Skip to content

Commit 0073310

Browse files
AustinMrozwebfiltered
authored andcommitted
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 <[email protected]>
1 parent a8ea4b5 commit 0073310

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lib/litegraph/src/subgraph/SubgraphNode.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
313313
widget: Readonly<IBaseWidget>
314314
) {
315315
// Use the first matching widget
316-
const promotedWidget = toConcreteWidget(widget, this).createCopyForNode(
317-
this
318-
)
316+
const targetWidget = toConcreteWidget(widget, this)
317+
const promotedWidget = targetWidget.createCopyForNode(this)
319318

320319
Object.assign(promotedWidget, {
321320
get name() {
@@ -370,7 +369,15 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
370369
subgraphNode: this
371370
})
372371

373-
input.widget = { name: subgraphInput.name }
372+
// NOTE: This code creates linked chains of prototypes for passing across
373+
// multiple levels of subgraphs. As part of this, it intentionally avoids
374+
// creating new objects. Have care when making changes.
375+
const backingInput =
376+
targetWidget.node.findInputSlot(widget.name, true)?.widget ?? {}
377+
input.widget ??= { name: subgraphInput.name }
378+
input.widget.name = subgraphInput.name
379+
Object.setPrototypeOf(input.widget, backingInput)
380+
374381
input._widget = promotedWidget
375382
}
376383

0 commit comments

Comments
 (0)