Fix DOM widgets disappear

This commit is contained in:
filtered
2025-05-15 08:37:21 +10:00
parent e6bae04a2c
commit ec4b0c960f

View File

@@ -798,26 +798,29 @@ export class ComfyApp {
LiteGraph.alt_drag_do_clone_nodes = true
LiteGraph.macGesturesRequireMac = false
this.canvas.canvas.addEventListener('litegraph:set-graph', (e) => {
type SetGraphType = CustomEvent<{
newGraph: LGraph | Subgraph
oldGraph: LGraph | Subgraph
}>
this.canvas.canvas.addEventListener<'litegraph:set-graph'>(
'litegraph:set-graph',
(e) => {
// Assertion: Not yet defined in litegraph.
const { newGraph } = e.detail
// Assertion: Not yet defined in litegraph.
const { newGraph } = (e as SetGraphType).detail
const nodeSet = new Set(newGraph.nodes)
const widgetStore = useDomWidgetStore()
const nodeSet = new Set(newGraph.nodes)
const widgetStore = useDomWidgetStore()
for (const { widget } of widgetStore.widgetStates.values()) {
// Assertions: UnwrapRef
if (nodeSet.has(widget.node as LGraphNode)) {
widgetStore.registerWidget(widget as BaseDOMWidget)
} else {
widgetStore.unregisterWidget(widget.id)
for (const { widget } of widgetStore.widgetStates.values()) {
if (!nodeSet.has(widget.node as LGraphNode)) {
widgetStore.unregisterWidget(widget.id)
}
}
for (const { widget } of widgetStore.inactiveWidgetStates.values()) {
if (nodeSet.has(widget.node as LGraphNode)) {
widgetStore.registerWidget(widget as BaseDOMWidget)
}
}
}
})
)
this.graph.start()