From 0924009f1121cb49ac61974af5d6eaecf0d9af70 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 10 Sep 2026 03:06:55 +0000 Subject: [PATCH] fix: refresh slot labels after rename with ECS node state (#17319) Fixes #16642 - Renaming an input or output slot now refreshes the rendered label immediately (regressed when the ECS node state landed in #14246). - Slot descriptors are exposed to the node shell through a reactive view, so any slot field edit propagates; no per-field handlers needed. - Regression test added (fails on main, passes here).
Full context for agent readers **Root cause.** Before ECS, `LGraphCanvas` listened for `node:slot-label:changed` and redrew. The ECS merge removed that handler and instead reads slot data through `createNodeShellState`. The plain objects in `node.inputs` / `node.outputs` are not reactive, so label writes never invalidated the shell state and the Vue node kept the old label. **Fix.** `src/lib/litegraph/src/node/slotDescriptorView.ts` adds a generic `createSlotView` Proxy (exported as `createInputSlotView` / `createOutputSlotView`, plus `resolveInputSlotView` for lookups). `createNodeShellState` in `src/core/graph/nodeShell/nodeShellState.ts` takes the two view factories and derives its slot arrays from them; `LGraphNode.ts` passes them through. Any write to a slot descriptor (label, name, type) now triggers the shell to recompute. **Tests.** `src/core/graph/nodeShell/slotLabelReactivity.regression.test.ts` (5 cases: input rename, output rename, rename after link, rename of a widget-backed input, rename via `renameSlot`). Written TDD: red on `main`, green on this branch. The test lives under `src/core/graph/nodeShell/` to satisfy the layer-boundary lint. `pnpm vitest run` on the three touched test files: 18/18. `pnpm typecheck` clean, `oxlint`/`eslint` clean. **Disclosure.** Knip (pre-push hook) flagged an unused `resolveOutputSlotView` export that I had added for symmetry; I removed it rather than leave dead code. Add it back if a caller appears. **Backport.** Labelled `needs-backport`, `core/1.53`, `cloud/1.53` per program policy (every ECS fix goes to 1.53 before promotion).
--------- Co-authored-by: Amp (cherry picked from commit 928cd4a5e56f0848a4e971b532e1db95a5f53c44) --- .../slotLabelReactivity.regression.test.ts | 29 ++++++++++++++++++ src/lib/litegraph/src/LGraphNode.ts | 2 ++ .../src/node/slotDescriptorView.test.ts | 16 ++++++++++ .../litegraph/src/node/slotDescriptorView.ts | 30 ++++++++++++++++++- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/core/graph/nodeShell/slotLabelReactivity.regression.test.ts diff --git a/src/core/graph/nodeShell/slotLabelReactivity.regression.test.ts b/src/core/graph/nodeShell/slotLabelReactivity.regression.test.ts new file mode 100644 index 00000000000..64f479230b1 --- /dev/null +++ b/src/core/graph/nodeShell/slotLabelReactivity.regression.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, test } from 'vitest' +import { computed, isReactive } from 'vue' + +import type { INodeOutputSlot } from '@/lib/litegraph/src/interfaces' +import { LGraphNode } from '@/lib/litegraph/src/litegraph' + +describe('slot label reactivity (regression #16642)', () => { + test('plain-object output written by index is upgraded and reactive', () => { + const node = new LGraphNode('Plain') + node.addOutput('out', 'STRING') + + const outLabel = computed(() => node.outputs[0].label) + expect(outLabel.value).toBeUndefined() + + const output: INodeOutputSlot = { + name: 'out', + type: 'STRING', + links: [], + boundingRect: new Float64Array(4) + } + node.outputs[0] = output + expect(outLabel.value).toBeUndefined() + + node.outputs[0].label = 'c' + + expect(outLabel.value).toBe('c') + expect(isReactive(node.outputs[0])).toBe(true) + }) +}) diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 3fb1eec569a..fb82b414c89 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -63,6 +63,7 @@ import { } from './node/slotLinks' import { createInputSlotView, + createOutputSlotView, resolveInputSlotView } from './node/slotDescriptorView' import { initializeWidgetsView } from './node/widgetsView' @@ -1047,6 +1048,7 @@ export class LGraphNode type, this.title_mode ) + this._state.outputs = createOutputSlotView(this, this._state.outputs) this._inputs = this._state.inputs this._outputs = this._state.outputs for (const property of [ diff --git a/src/lib/litegraph/src/node/slotDescriptorView.test.ts b/src/lib/litegraph/src/node/slotDescriptorView.test.ts index dc9a66ccace..b911eb7cf55 100644 --- a/src/lib/litegraph/src/node/slotDescriptorView.test.ts +++ b/src/lib/litegraph/src/node/slotDescriptorView.test.ts @@ -60,6 +60,22 @@ describe('slot identity', () => { expect(node._state.inputs[0]).toBe(node.inputs[0]) }) + it('upgrades extension-assigned outputs when they are written', () => { + const node = new LGraphNode('Node') + const output = { + name: 'output', + type: 'INT', + links: [], + boundingRect: new Float64Array(4) + } + + node.outputs = [output] + + expect(node._state.outputs).toBe(node.outputs) + expect(node.outputs[0]).toBeInstanceOf(NodeOutputSlot) + expect(node._state.outputs[0]).toBe(node.outputs[0]) + }) + it('preserves native indexOf behavior for arbitrary values', () => { const node = new LGraphNode('Node') node.addInput('slot', 'INT') diff --git a/src/lib/litegraph/src/node/slotDescriptorView.ts b/src/lib/litegraph/src/node/slotDescriptorView.ts index af519cd9f37..41f83671b6c 100644 --- a/src/lib/litegraph/src/node/slotDescriptorView.ts +++ b/src/lib/litegraph/src/node/slotDescriptorView.ts @@ -1,6 +1,10 @@ import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { INodeInputSlot } from '@/lib/litegraph/src/interfaces' +import type { + INodeInputSlot, + INodeOutputSlot +} from '@/lib/litegraph/src/interfaces' import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' +import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' import { toClass } from '@/lib/litegraph/src/utils/type' const assignedInputViews = new WeakMap< @@ -28,6 +32,21 @@ export function createInputSlotView( return view } +export function createOutputSlotView( + node: LGraphNode, + outputs: INodeOutputSlot[] +): INodeOutputSlot[] { + return new Proxy(outputs, { + set(target, property, value: unknown, receiver) { + const output = + isArrayIndex(property) && isOutputSlot(value) + ? toClass(NodeOutputSlot, value, node) + : value + return Reflect.set(target, property, output, receiver) + } + }) +} + export function resolveInputSlotView( inputs: INodeInputSlot[], input: INodeInputSlot @@ -54,3 +73,12 @@ function isInputSlot(value: unknown): value is INodeInputSlot { 'type' in value ) } + +function isOutputSlot(value: unknown): value is INodeOutputSlot { + return ( + value !== null && + typeof value === 'object' && + 'name' in value && + 'type' in value + ) +}