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 <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-02-03 13:36:36 -08:00
parent fcd83d84a3
commit 85c6bd132c
3 changed files with 11 additions and 0 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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')
})