[backport cloud/1.40] fix: sync DOM widget values to widgetValueStore on registration (#9174)

Backport of #9166 to cloud/1.40

Manually created.

Co-authored-by: Hunter <huntcsg@users.noreply.github.com>
This commit is contained in:
AustinMroz
2026-02-24 10:47:43 -08:00
committed by GitHub
parent 4daba09415
commit c7cbefc256
2 changed files with 62 additions and 0 deletions

View File

@@ -7,12 +7,14 @@ import {
LegacyWidget,
LiteGraph
} from '@/lib/litegraph/src/litegraph'
import type { NodeId } from '@/lib/litegraph/src/litegraph'
import type {
IBaseWidget,
IWidgetOptions
} from '@/lib/litegraph/src/types/widgets'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { useDomWidgetStore } from '@/stores/domWidgetStore'
import { useWidgetValueStore } from '@/stores/widgetValueStore'
import { generateUUID } from '@/utils/formatUtil'
export interface BaseDOMWidget<
@@ -148,6 +150,18 @@ abstract class BaseDOMWidgetImpl<V extends object | string>
this.callback?.(this.value)
}
override setNodeId(nodeId: NodeId): void {
// Capture the DOM-resolved value before registration, since the base class
// registers _state.value which is undefined for DOM widgets (their value
// lives in the DOM element / options.getValue).
const resolvedValue = this.value
super.setNodeId(nodeId)
const graphId = this.node.graph?.rootGraph.id
if (!graphId) return
const state = useWidgetValueStore().getWidget(nodeId, this.name)
if (state) state.value = resolvedValue
}
get margin(): number {
return this.options.margin ?? BaseDOMWidgetImpl.DEFAULT_MARGIN
}

View File

@@ -0,0 +1,48 @@
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
import { DOMWidgetImpl } from '@/scripts/domWidget'
import { useWidgetValueStore } from '@/stores/widgetValueStore'
describe('DOMWidgetImpl store integration', () => {
let graph: LGraph
let node: LGraphNode
let store: ReturnType<typeof useWidgetValueStore>
beforeEach(() => {
setActivePinia(createTestingPinia({ stubActions: false }))
store = useWidgetValueStore()
graph = new LGraph()
node = new LGraphNode('TestNode')
node.id = 1
graph.add(node)
})
it('registers DOM-resolved value in store via setNodeId', () => {
const defaultValue = 'You are an expert image-generation engine.'
const element = document.createElement('textarea')
element.value = defaultValue
const widget = new DOMWidgetImpl({
node,
name: 'system_prompt',
type: 'customtext',
element,
options: {
getValue: () => element.value as string,
setValue: (v: string) => {
element.value = v
const state = store.getWidget(node.id, 'system_prompt')
if (state) state.value = v
}
}
})
widget.setNodeId(node.id)
const state = store.getWidget(node.id, 'system_prompt')
expect(state?.value).toBe(defaultValue)
})
})