@@ -4,11 +4,14 @@ import { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas'
4
4
import { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
5
5
import { LLink , type ResolvedConnection } from '@/lib/litegraph/src/LLink'
6
6
import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError'
7
- import type { ISubgraphInput } from '@/lib/litegraph/src/interfaces'
8
- import {
9
- type INodeInputSlot ,
10
- type ISlotType ,
11
- type NodeId
7
+ import type {
8
+ ISubgraphInput ,
9
+ IWidgetLocator
10
+ } from '@/lib/litegraph/src/interfaces'
11
+ import type {
12
+ INodeInputSlot ,
13
+ ISlotType ,
14
+ NodeId
12
15
} from '@/lib/litegraph/src/litegraph'
13
16
import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot'
14
17
import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot'
@@ -78,9 +81,10 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
78
81
const existingInput = this . inputs . find ( ( i ) => i . name == name )
79
82
if ( existingInput ) {
80
83
const linkId = subgraphInput . linkIds [ 0 ]
81
- const { inputNode } = subgraph . links [ linkId ] . resolve ( subgraph )
84
+ const { inputNode, input } = subgraph . links [ linkId ] . resolve ( subgraph )
82
85
const widget = inputNode ?. widgets ?. find ?.( ( w ) => w . name == name )
83
- if ( widget ) this . #setWidget( subgraphInput , existingInput , widget )
86
+ if ( widget )
87
+ this . #setWidget( subgraphInput , existingInput , widget , input ?. widget )
84
88
return
85
89
}
86
90
const input = this . addInput ( name , type )
@@ -185,13 +189,14 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
185
189
186
190
subgraphInput . events . addEventListener (
187
191
'input-connected' ,
188
- ( ) => {
192
+ ( e ) => {
189
193
if ( input . _widget ) return
190
194
191
195
const widget = subgraphInput . _widget
192
196
if ( ! widget ) return
193
197
194
- this . #setWidget( subgraphInput , input , widget )
198
+ const widgetLocator = e . detail . input . widget
199
+ this . #setWidget( subgraphInput , input , widget , widgetLocator )
195
200
} ,
196
201
{ signal }
197
202
)
@@ -301,7 +306,7 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
301
306
const widget = resolved . inputNode . getWidgetFromSlot ( resolved . input )
302
307
if ( ! widget ) continue
303
308
304
- this . #setWidget( subgraphInput , input , widget )
309
+ this . #setWidget( subgraphInput , input , widget , resolved . input . widget )
305
310
break
306
311
}
307
312
}
@@ -310,11 +315,13 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
310
315
#setWidget(
311
316
subgraphInput : Readonly < SubgraphInput > ,
312
317
input : INodeInputSlot ,
313
- widget : Readonly < IBaseWidget >
318
+ widget : Readonly < IBaseWidget > ,
319
+ inputWidget : IWidgetLocator | undefined
314
320
) {
315
321
// Use the first matching widget
316
- const targetWidget = toConcreteWidget ( widget , this )
317
- const promotedWidget = targetWidget . createCopyForNode ( this )
322
+ const promotedWidget = toConcreteWidget ( widget , this ) . createCopyForNode (
323
+ this
324
+ )
318
325
319
326
Object . assign ( promotedWidget , {
320
327
get name ( ) {
@@ -372,11 +379,9 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
372
379
// NOTE: This code creates linked chains of prototypes for passing across
373
380
// multiple levels of subgraphs. As part of this, it intentionally avoids
374
381
// creating new objects. Have care when making changes.
375
- const backingInput =
376
- targetWidget . node . findInputSlot ( widget . name , true ) ?. widget ?? { }
377
382
input . widget ??= { name : subgraphInput . name }
378
383
input . widget . name = subgraphInput . name
379
- Object . setPrototypeOf ( input . widget , backingInput )
384
+ if ( inputWidget ) Object . setPrototypeOf ( input . widget , inputWidget )
380
385
381
386
input . _widget = promotedWidget
382
387
}
0 commit comments