Skip to content

Commit 4cc6a15

Browse files
Fix refresh combos command fails on nodes using V2 spec (#3848)
1 parent 3f50b8b commit 4cc6a15

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

.github/workflows/test-ui.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
with:
3131
repository: 'Comfy-Org/ComfyUI_devtools'
3232
path: 'ComfyUI/custom_nodes/ComfyUI_devtools'
33-
ref: '9d2421fd3208a310e4d0f71fca2ea0c985759c33'
33+
ref: 'd05fd48dd787a4192e16802d4244cfcc0e2f9684'
3434

3535
- uses: actions/setup-node@v4
3636
with:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"id": "5635564e-189f-49e4-9b25-6b7634bcd595",
3+
"revision": 0,
4+
"last_node_id": 78,
5+
"last_link_id": 53,
6+
"nodes": [
7+
{
8+
"id": 78,
9+
"type": "DevToolsNodeWithV2ComboInput",
10+
"pos": [1320, 904],
11+
"size": [270.3199157714844, 58],
12+
"flags": {},
13+
"order": 0,
14+
"mode": 0,
15+
"inputs": [],
16+
"outputs": [
17+
{
18+
"name": "COMBO",
19+
"type": "COMBO",
20+
"links": null
21+
}
22+
],
23+
"properties": {
24+
"Node name for S&R": "DevToolsNodeWithV2ComboInput"
25+
},
26+
"widgets_values": ["A"]
27+
}
28+
],
29+
"links": [],
30+
"groups": [],
31+
"config": {},
32+
"extra": {
33+
"frontendVersion": "1.19.7"
34+
},
35+
"version": 0.4
36+
}

browser_tests/tests/widget.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ test.describe('Combo text widget', () => {
5353
const refreshedComboValues = await getComboValues()
5454
expect(refreshedComboValues).not.toEqual(initialComboValues)
5555
})
56+
57+
test('Should refresh combo values of nodes with v2 combo input spec', async ({
58+
comfyPage
59+
}) => {
60+
await comfyPage.loadWorkflow('node_with_v2_combo_input')
61+
// click canvas to focus
62+
await comfyPage.page.mouse.click(400, 300)
63+
// press R to trigger refresh
64+
await comfyPage.page.keyboard.press('r')
65+
// wait for nodes' widgets to be updated
66+
await comfyPage.page.mouse.click(400, 300)
67+
await comfyPage.nextFrame()
68+
// get the combo widget's values
69+
const comboValues = await comfyPage.page.evaluate(() => {
70+
return window['app'].graph.nodes
71+
.find((node) => node.title === 'Node With V2 Combo Input')
72+
.widgets.find((widget) => widget.name === 'combo_input').options.values
73+
})
74+
expect(comboValues).toEqual(['A', 'B'])
75+
})
5676
})
5777

5878
test.describe('Boolean widget', () => {

src/scripts/app.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import {
2525
type ModelFile,
2626
type NodeId
2727
} from '@/schemas/comfyWorkflowSchema'
28-
import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema'
28+
import {
29+
type ComfyNodeDef as ComfyNodeDefV1,
30+
isComboInputSpecV1,
31+
isComboInputSpecV2
32+
} from '@/schemas/nodeDefSchema'
2933
import { getFromWebmFile } from '@/scripts/metadata/ebml'
3034
import { getGltfBinaryMetadata } from '@/scripts/metadata/gltf'
3135
import { getFromIsobmffFile } from '@/scripts/metadata/isobmff'
@@ -1572,12 +1576,26 @@ export class ComfyApp {
15721576
if (!def?.input) continue
15731577

15741578
if (node.widgets) {
1579+
const nodeInputs = def.input
15751580
for (const widget of node.widgets) {
15761581
if (widget.type === 'combo') {
1577-
if (def['input'].required?.[widget.name] !== undefined) {
1578-
widget.options.values = def['input'].required[widget.name][0]
1579-
} else if (def['input'].optional?.[widget.name] !== undefined) {
1580-
widget.options.values = def['input'].optional[widget.name][0]
1582+
let inputType: 'required' | 'optional' | undefined
1583+
if (nodeInputs.required?.[widget.name] !== undefined) {
1584+
inputType = 'required'
1585+
} else if (nodeInputs.optional?.[widget.name] !== undefined) {
1586+
inputType = 'optional'
1587+
}
1588+
if (inputType !== undefined) {
1589+
// Get the input spec associated with the widget
1590+
const inputSpec = nodeInputs[inputType]?.[widget.name]
1591+
if (inputSpec) {
1592+
// Refresh the combo widget's options with the values from the input spec
1593+
if (isComboInputSpecV2(inputSpec)) {
1594+
widget.options.values = inputSpec[1]?.options
1595+
} else if (isComboInputSpecV1(inputSpec)) {
1596+
widget.options.values = inputSpec[0]
1597+
}
1598+
}
15811599
}
15821600
}
15831601
}

0 commit comments

Comments
 (0)