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>
This commit is contained in:
AustinMroz
2025-09-11 14:27:44 -07:00
committed by GitHub
parent 46f4ce3890
commit 68845ce33a

View File

@@ -313,9 +313,8 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
widget: Readonly<IBaseWidget>
) {
// 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
}