From 85c6bd132cccde491dcd538dfc95af96cd620cf8 Mon Sep 17 00:00:00 2001 From: Alexander Brown <448862+DrJKL@users.noreply.github.com> Date: Tue, 3 Feb 2026 13:36:36 -0800 Subject: [PATCH] feat: LGraphNode.addCustomWidget wires widget to node ID Amp-Thread-ID: https://ampcode.com/threads/T-019c2567-2a52-7010-a85e-79eb76be24a1 Co-authored-by: Amp --- src/lib/litegraph/src/LGraphNode.test.ts | 3 +++ src/lib/litegraph/src/LGraphNode.ts | 5 +++++ src/lib/litegraph/src/LGraphNode.widgetOrder.test.ts | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/lib/litegraph/src/LGraphNode.test.ts b/src/lib/litegraph/src/LGraphNode.test.ts index 5b498dac34..6ee5049a1c 100644 --- a/src/lib/litegraph/src/LGraphNode.test.ts +++ b/src/lib/litegraph/src/LGraphNode.test.ts @@ -1,3 +1,5 @@ +import { createTestingPinia } from '@pinia/testing' +import { setActivePinia } from 'pinia' import { afterEach, beforeEach, describe, expect, vi } from 'vitest' import type { @@ -42,6 +44,7 @@ describe('LGraphNode', () => { let origLiteGraph: typeof LiteGraph beforeEach(() => { + setActivePinia(createTestingPinia({ stubActions: false })) origLiteGraph = Object.assign({}, LiteGraph) // @ts-expect-error Intended: Force remove an otherwise readonly non-optional property delete origLiteGraph.Classes diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index baf6a44190..f6cb31d493 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1957,6 +1957,11 @@ export class LGraphNode this.widgets ||= [] const widget = toConcreteWidget(custom_widget, this, false) ?? custom_widget this.widgets.push(widget) + + if ('setNodeId' in widget && typeof widget.setNodeId === 'function') { + widget.setNodeId(this.id) + } + return widget } diff --git a/src/lib/litegraph/src/LGraphNode.widgetOrder.test.ts b/src/lib/litegraph/src/LGraphNode.widgetOrder.test.ts index 21f7a7cd8b..4e7b8f44ef 100644 --- a/src/lib/litegraph/src/LGraphNode.widgetOrder.test.ts +++ b/src/lib/litegraph/src/LGraphNode.widgetOrder.test.ts @@ -1,3 +1,5 @@ +import { createTestingPinia } from '@pinia/testing' +import { setActivePinia } from 'pinia' import { beforeEach, describe, expect, it } from 'vitest' import { LGraphNode } from '@/lib/litegraph/src/litegraph' @@ -8,6 +10,7 @@ describe('LGraphNode widget ordering', () => { let node: LGraphNode beforeEach(() => { + setActivePinia(createTestingPinia({ stubActions: false })) node = new LGraphNode('TestNode') })