fix: sync input._widget refs and widgets_values for litegraph mode

After syncPromotedWidgets replaces copies with PromotedWidgetSlots, update input._widget references so litegraph lifecycle events (removal, renaming) target the correct instances.

Also fix widgets_values restoration to find slot-promoted widgets via input._widget when the PromotedWidgetSlot name differs from the slot name.

Amp-Thread-ID: https://ampcode.com/threads/T-019c54cb-77f0-736a-a619-a530cdb8da86
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-02-12 18:38:27 -08:00
parent 69c4ab6c32
commit 6140d22423

View File

@@ -79,11 +79,16 @@ function syncPromotedWidgets(
// subgraph input links so they use the same delegation as context-menu
// promoted widgets.
const subgraphNode = node as SubgraphNode
// Map from slot name → PromotedWidgetSlot for syncing input._widget refs
const slotsByName = new Map<string, PromotedWidgetSlot>()
const newSlots: IBaseWidget[] = parsed.flatMap(([nodeId, widgetName]) => {
if (nodeId === '-1') {
const source = resolveSlotPromotedSource(subgraphNode, widgetName)
if (source)
return [new PromotedWidgetSlot(subgraphNode, source[0], source[1])]
if (source) {
const slot = new PromotedWidgetSlot(subgraphNode, source[0], source[1])
slotsByName.set(widgetName, slot)
return [slot]
}
const widget = nativeWidgets.find((w) => w.name === widgetName)
return widget ? [widget] : []
}
@@ -91,6 +96,13 @@ function syncPromotedWidgets(
})
node.widgets.push(...newSlots)
// Sync input._widget references so litegraph lifecycle events
// (removal, renaming) target the new PromotedWidgetSlot instances.
for (const input of subgraphNode.inputs) {
const slot = slotsByName.get(input.name)
if (slot) input._widget = slot
}
canvasStore.canvas?.setDirty(true, true)
node._setConcreteSlots()
node.arrange()
@@ -150,10 +162,14 @@ const onConfigure = function (
if (serialisedNode.properties?.proxyWidgets) {
syncPromotedWidgets(this, serialisedNode.properties.proxyWidgets)
const parsed = parseProxyWidgets(serialisedNode.properties.proxyWidgets)
const subNode = this as SubgraphNode
serialisedNode.widgets_values?.forEach((v, index) => {
if (parsed[index]?.[0] !== '-1') return
const widget = this.widgets.find((w) => w.name == parsed[index][1])
if (v !== null && widget) widget.value = v
if (parsed[index]?.[0] !== '-1' || v === null) return
const slotName = parsed[index][1]
const widget =
this.widgets.find((w) => w.name === slotName) ??
subNode.inputs.find((inp) => inp.name === slotName)?._widget
if (widget) widget.value = v
})
}
}