diff --git a/src/composables/graph/useGraphNodeManager.test.ts b/src/composables/graph/useGraphNodeManager.test.ts index f0c4c3d66e..95378335a0 100644 --- a/src/composables/graph/useGraphNodeManager.test.ts +++ b/src/composables/graph/useGraphNodeManager.test.ts @@ -241,6 +241,32 @@ describe('Widget slotMetadata reactivity on link disconnect', () => { expect(widgetData?.slotMetadata?.linked).toBe(false) }) + + it('clears stale slotMetadata when input no longer matches widget', async () => { + const { graph, node } = createWidgetInputGraph() + const { vueNodeData } = useGraphNodeManager(graph) + + const nodeData = vueNodeData.get(String(node.id))! + const widgetData = nodeData.widgets!.find((w) => w.name === 'prompt')! + + expect(widgetData.slotMetadata?.linked).toBe(true) + + node.inputs[0].name = 'other' + node.inputs[0].widget = { name: 'other' } + node.inputs[0].link = null + + graph.trigger('node:slot-links:changed', { + nodeId: node.id, + slotType: NodeSlotType.INPUT, + slotIndex: 0, + connected: false, + linkId: 42 + }) + + await nextTick() + + expect(widgetData.slotMetadata).toBeUndefined() + }) }) describe('Subgraph output slot label reactivity', () => { diff --git a/src/composables/graph/useGraphNodeManager.ts b/src/composables/graph/useGraphNodeManager.ts index 4c87b68355..a56812040f 100644 --- a/src/composables/graph/useGraphNodeManager.ts +++ b/src/composables/graph/useGraphNodeManager.ts @@ -520,8 +520,7 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { // Update only widgets with new slot metadata, keeping other widget data intact for (const widget of currentData.widgets ?? []) { - const slotInfo = slotMetadata.get(widget.slotName ?? widget.name) - if (slotInfo) widget.slotMetadata = slotInfo + widget.slotMetadata = slotMetadata.get(widget.slotName ?? widget.name) } }