Prune widgets on graph configure (#3716)

This commit is contained in:
Chenlei Hu
2025-05-01 16:07:42 -04:00
committed by GitHub
parent f868fac6e9
commit 4461210f43
2 changed files with 18 additions and 0 deletions

View File

@@ -314,3 +314,18 @@ LGraphNode.prototype.addDOMWidget = function <
return widget
}
/**
* Prunes widgets that are no longer in the graph.
* @param nodes The nodes to prune widgets for.
*/
export const pruneWidgets = (nodes: LGraphNode[]) => {
const nodeSet = new Set(nodes)
const domWidgetStore = useDomWidgetStore()
for (const widgetState of domWidgetStore.widgetStates.values()) {
const widget = widgetState.widget
if (!nodeSet.has(widget.node as LGraphNode)) {
domWidgetStore.unregisterWidget(widget.id)
}
}
}