From ea6a4ef781f621656666ffa96c41722f58b94573 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 11 Sep 2026 18:41:47 +0000 Subject: [PATCH 1/6] fix(litegraph): keep promoted dynamic combo child links on load A dynamic combo lays out the default option's child inputs when the node is created, and `ComfyNode.configure` appends the serialized inputs that option does not define. Serialized `target_slot` values count the saved layout, so a link into a non-default option's child lands on the wrong slot; applying the combo's serialized value then rebuilds the group and hands the link to an input the selected option does not define, dropping it. Through a subgraph boundary that demotes the promoted widget to a disconnected input slot and auto-promotes a duplicate `_1`. Realign group widget child input links by name before widget values are applied. Scoped to those inputs: `LGraph.configure` runs the full pass once every node is configured, which is how it resolves contention for a slot between nodes. --- ...subgraph-dynamic-combo-promoted-child.json | 241 ++++++++++++++++++ .../subgraphPromotedDynamicComboChild.spec.ts | 42 +++ .../src/LGraph.inputSlotRealign.test.ts | 82 ++++++ src/lib/litegraph/src/LGraphNode.ts | 3 + src/lib/litegraph/src/linkDeduplication.ts | 50 ++++ 5 files changed, 418 insertions(+) create mode 100644 browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json create mode 100644 browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts diff --git a/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json b/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json new file mode 100644 index 00000000000..a2524f3cda2 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json @@ -0,0 +1,241 @@ +{ + "id": "f1e2d3c4-0000-4000-8000-fe25800258ff", + "revision": 0, + "last_node_id": 67, + "last_link_id": 2, + "nodes": [ + { + "id": 1, + "type": "LoadImage", + "pos": [80, 120], + "size": [274, 314], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { + "localized_name": "IMAGE", + "name": "IMAGE", + "type": "IMAGE", + "links": [1] + }, + { + "localized_name": "MASK", + "name": "MASK", + "type": "MASK", + "links": [] + } + ], + "properties": { + "cnr_id": "comfy-core", + "ver": "0.27.0", + "Node name for S&R": "LoadImage" + }, + "widgets_values": ["watch_macro_shot.png", "image"] + }, + { + "id": 66, + "type": "7c0d9e16-1d55-4f2e-9a61-fe2580258001", + "pos": [460, 120], + "size": [280, 120], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "image", + "name": "image", + "type": "IMAGE", + "link": 1 + }, + { + "localized_name": "resize_type.multiplier", + "name": "resize_type.multiplier", + "type": "FLOAT", + "label": "scale_multiplier", + "widget": { + "name": "resize_type.multiplier" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "resized", + "name": "resized", + "type": "IMAGE", + "links": [2] + } + ], + "properties": {}, + "widgets_values": [4] + }, + { + "id": 67, + "type": "PreviewImage", + "pos": [820, 120], + "size": [210, 246], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [ + { + "localized_name": "images", + "name": "images", + "type": "IMAGE", + "link": 2 + } + ], + "outputs": [], + "properties": {}, + "widgets_values": [] + } + ], + "links": [ + { + "id": 1, + "origin_id": 1, + "origin_slot": 0, + "target_id": 66, + "target_slot": 0, + "type": "IMAGE" + }, + { + "id": 2, + "origin_id": 66, + "origin_slot": 0, + "target_id": 67, + "target_slot": 0, + "type": "IMAGE" + } + ], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "7c0d9e16-1d55-4f2e-9a61-fe2580258001", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 57, + "lastLinkId": 50, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Resize Image Subgraph", + "inputNode": { + "id": -10, + "bounding": [420, 60, 190, 80] + }, + "outputNode": { + "id": -20, + "bounding": [980, 100, 128, 68] + }, + "inputs": [ + { + "id": "e981cdcd-e740-4932-91e0-06392d5ac526", + "name": "image", + "type": "IMAGE", + "linkIds": [45], + "localized_name": "image", + "pos": [587, 85] + }, + { + "id": "df3b8dbd-5649-4dbd-8551-c5cb254eafc5", + "name": "resize_type.multiplier", + "type": "FLOAT", + "linkIds": [50], + "label": "scale_multiplier", + "pos": [587, 105] + } + ], + "outputs": [ + { + "id": "517ebe35-9129-4f66-a88e-2fdca4c417cf", + "name": "resized", + "type": "IMAGE", + "linkIds": [24], + "localized_name": "resized", + "pos": [1000, 130] + } + ], + "widgets": [], + "nodes": [ + { + "id": 57, + "type": "ResizeImageMaskNode", + "pos": [700, 120], + "size": [270, 106], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "input", + "name": "input", + "type": "IMAGE,MASK", + "link": 45 + }, + { + "localized_name": "resize_type.multiplier", + "name": "resize_type.multiplier", + "type": "FLOAT", + "widget": { + "name": "resize_type.multiplier" + }, + "link": 50 + } + ], + "outputs": [ + { + "localized_name": "resized", + "name": "resized", + "type": "IMAGE", + "links": [24] + } + ], + "properties": { + "cnr_id": "comfy-core", + "ver": "0.27.0", + "Node name for S&R": "ResizeImageMaskNode" + }, + "widgets_values": ["scale by multiplier", 4, "lanczos"] + } + ], + "groups": [], + "links": [ + { + "id": 45, + "origin_id": -10, + "origin_slot": 0, + "target_id": 57, + "target_slot": 0, + "type": "IMAGE" + }, + { + "id": 50, + "origin_id": -10, + "origin_slot": 1, + "target_id": 57, + "target_slot": 1, + "type": "FLOAT" + }, + { + "id": 24, + "origin_id": 57, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "IMAGE" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": {}, + "version": 0.4 +} diff --git a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts new file mode 100644 index 00000000000..262c61ea508 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts @@ -0,0 +1,42 @@ +import { expect } from '@playwright/test' + +import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' +import { getPromotedWidgetNames } from '@e2e/fixtures/utils/promotedWidgets' + +// Reduced from the `utility_seedvr2_3b_int8_upscale_image` template (FE-258): +// a `ResizeImageMaskNode` whose `resize_type` dynamic combo is set to a +// non-default option, with that option's `multiplier` child widget promoted +// through the subgraph boundary. +const WORKFLOW = 'subgraphs/subgraph-dynamic-combo-promoted-child' +const HOST_NODE_TITLE = 'Resize Image Subgraph' +const HOST_NODE_ID = '66' +const PROMOTED_WIDGET_LABEL = 'scale_multiplier' +const PROMOTED_INPUT_NAME = 'resize_type.multiplier' + +test.describe( + 'Promoted dynamic combo child widget', + { tag: ['@subgraph', '@widget', '@vue-nodes'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true) + }) + + test('survives a workflow load', async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow(WORKFLOW) + await comfyPage.vueNodes.waitForNodes() + + const multiplier = comfyPage.vueNodes.getWidgetRowByLabel( + HOST_NODE_TITLE, + PROMOTED_WIDGET_LABEL + ) + await expect(multiplier).toBeVisible() + await expect( + comfyPage.vueNodes.getInputNumberControls(multiplier).input + ).toHaveValue('4.00') + + await expect + .poll(() => getPromotedWidgetNames(comfyPage, HOST_NODE_ID)) + .toEqual([PROMOTED_INPUT_NAME]) + }) + } +) diff --git a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts index bd718277661..cb96ff0c09a 100644 --- a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts +++ b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts @@ -8,6 +8,7 @@ import { import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import { normalizeConfiguredTopology, + realignGroupWidgetChildLinks, realignInputLinkSlots } from '@/lib/litegraph/src/linkDeduplication' import type { @@ -784,3 +785,84 @@ describe('realignInputLinkSlots', () => { expect(movable.target_slot).toBe(4) }) }) + +describe('realignGroupWidgetChildLinks (FE-258)', () => { + function groupWidgetSetup(inputNames: string[], groupWidgetName: string) { + const graph = new LGraph() + const source = new LGraphNode('Source') + source.addOutput('out', 'number') + const target = new LGraphNode('Target') + for (const name of inputNames) target.addInput(name, 'number') + target.addWidget('combo', groupWidgetName, 'scale dimensions', () => {}, { + values: ['scale dimensions', 'scale by multiplier'] + }) + graph.add(source) + graph.add(target) + return { graph, source, target } + } + + function serializedInputs( + target: LGraphNode, + links: Record + ) { + return target.inputs.map((input) => ({ + name: input.name, + type: 'number', + link: links[input.name] ?? null + })) + } + + it('moves a child link off the slot the default option laid out', () => { + const { graph, source, target } = groupWidgetSetup( + ['input', 'resize_type.width', 'resize_type', 'resize_type.multiplier'], + 'resize_type' + ) + const link = source.connect(0, target, 1)! + + realignGroupWidgetChildLinks(target, { + id: target.id, + inputs: serializedInputs(target, { 'resize_type.multiplier': link.id }) + }) + + expect(link.target_slot).toBe(3) + expect( + useLinkStore().getInputSlotLink(graphScopeOf(graph), target.id, 3)?.id + ).toBe(link.id) + }) + + it('leaves inputs that no group widget owns', () => { + const { source, target } = groupWidgetSetup( + ['first', 'second', 'resize_type'], + 'resize_type' + ) + const link = source.connect(0, target, 0)! + + realignGroupWidgetChildLinks(target, { + id: target.id, + inputs: serializedInputs(target, { second: link.id }) + }) + + expect(link.target_slot).toBe(0) + }) + + it('leaves the children of a group nested inside a group widget', () => { + const { source, target } = groupWidgetSetup( + [ + 'model.reference_images.image_1', + 'other', + 'model.reference_images.mask' + ], + 'model' + ) + const link = source.connect(0, target, 1)! + + realignGroupWidgetChildLinks(target, { + id: target.id, + inputs: serializedInputs(target, { + 'model.reference_images.image_1': link.id + }) + }) + + expect(link.target_slot).toBe(1) + }) +}) diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 23242968361..b8e9609812f 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -55,6 +55,7 @@ import { badgeDrawObjects, badgeRows } from './nodeBadgeDraw' import { LGraphButton } from './LGraphButton' import type { LGraphButtonOptions } from './LGraphButton' import { LGraphCanvas } from './LGraphCanvas' +import { realignGroupWidgetChildLinks } from './linkDeduplication' import { LLink, replaceLinkTopology, slotFloatingLinks } from './LLink' import { inputHasLink, @@ -1165,6 +1166,8 @@ export class LGraphNode // SubgraphNode callback. this._internalConfigureAfterSlots?.() + realignGroupWidgetChildLinks(this, info) + const restoration = createWidgetRestorationState( info, this.constructor.nodeData?.fallbackWidgetsValuesNames diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 85014d1254e..42cabf75246 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -7,6 +7,7 @@ import { toNodeId } from '@/types/nodeId' import type { NodeId } from '@/types/nodeId' import cloneDeep from 'es-toolkit/compat/cloneDeep' import type { LGraph } from './LGraph' +import type { LGraphNode } from './LGraphNode' import type { LinkId, LLink, SerialisedLLinkArray } from './LLink' import type { ExportedSubgraph, @@ -176,6 +177,55 @@ export function detachSerialisedLinks( return linkByInputName } +/** + * Whether `inputName` is a child input of a group widget on `node`. + * + * Group widgets (dynamic combos) name their child inputs + * `.` and replace the whole set whenever their own + * value changes. The group is the segment before the *last* dot, so inputs of + * a nested dynamic group — autogrow names its children + * `..` — resolve to their own group and are excluded. + */ +function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { + if (!inputName) return false + + const separator = inputName.lastIndexOf('.') + if (separator < 1) return false + + const groupName = inputName.slice(0, separator) + return node.widgets?.some((widget) => widget.name === groupName) ?? false +} + +/** + * Realigns the links of a node's group widget child inputs, before the group + * widget's serialized value is applied. + * + * Applying that value rebuilds every child input of the group and hands each + * surviving link to the new input of the same name. A link sitting on the + * wrong slot — the node definition lays out the default option's children, + * while `target_slot` counts the serialized layout — is handed to an input + * that the selected option does not define, and is dropped. + * + * Only group widget children are realigned: {@link LGraph.configure} runs the + * full pass once every node is configured, which is what lets it resolve + * contention for a slot between nodes. Realigning a node's other inputs here + * would claim slots from nodes that have not configured yet. + */ +export function realignGroupWidgetChildLinks( + node: LGraphNode, + nodeData: Pick +): void { + const { graph } = node + if (!graph) return + + const inputs = nodeData.inputs?.filter((input) => + isGroupWidgetChildInput(node, input.name) + ) + if (!inputs?.length) return + + realignInputLinkSlots(graph, [[node.id, { id: nodeData.id, inputs }]]) +} + /** * Re-points each link's `target_slot` at the configured input with the same * name as the serialized input that references it. Replays moved connections From 7bff1a82a611f7c0487749b363cee960c2ff76d4 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 11 Sep 2026 20:44:50 +0000 Subject: [PATCH 2/6] fix(litegraph): resolve slot contention in the early realignment Review follow-ups: - Realign the node's ordinary inputs alongside its group widget children, so a link still occupying a child's destination slot moves in the same atomic update instead of blocking it. Slot keys are per graph/node/slot, so this cannot claim a slot from a node that has not configured yet. - Keep nested dynamic groups out of the batch. Their slots grow and renumber while the graph configures, and realigning them this early destroys their links (subgraphConvertAutogrowInputs, "loads with both reference images connected", reproduced 1/1 failing). - Fix the fixture's root links: a 0.4 schema graph serializes links as tuples, so the object form left both root links unparsed. Assert they survive load. - Cover the call site: a node mirroring ComfyNode's input reorder records the link on its child slot when the group widget value is applied. --- ...subgraph-dynamic-combo-promoted-child.json | 18 +- .../subgraphPromotedDynamicComboChild.spec.ts | 18 ++ .../src/LGraph.inputSlotRealign.test.ts | 155 +++++++++++++++++- src/lib/litegraph/src/linkDeduplication.ts | 71 +++++--- 4 files changed, 213 insertions(+), 49 deletions(-) diff --git a/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json b/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json index a2524f3cda2..d7293a2558b 100644 --- a/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json +++ b/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json @@ -93,22 +93,8 @@ } ], "links": [ - { - "id": 1, - "origin_id": 1, - "origin_slot": 0, - "target_id": 66, - "target_slot": 0, - "type": "IMAGE" - }, - { - "id": 2, - "origin_id": 66, - "origin_slot": 0, - "target_id": 67, - "target_slot": 0, - "type": "IMAGE" - } + [1, 1, 0, 66, 0, "IMAGE"], + [2, 66, 0, 67, 0, "IMAGE"] ], "groups": [], "definitions": { diff --git a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts index 262c61ea508..916fa9eb297 100644 --- a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts +++ b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts @@ -38,5 +38,23 @@ test.describe( .poll(() => getPromotedWidgetNames(comfyPage, HOST_NODE_ID)) .toEqual([PROMOTED_INPUT_NAME]) }) + + test('keeps the links of the nodes around it', async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow(WORKFLOW) + await comfyPage.vueNodes.waitForNodes() + + await expect + .poll(() => + comfyPage.page.evaluate(() => + [...window.app!.graph.links.values()] + .map( + (link) => + `${link.origin_id}:${link.origin_slot}->${link.target_id}:${link.target_slot}` + ) + .sort() + ) + ) + .toEqual(['1:0->66:0', '66:0->67:0']) + }) } ) diff --git a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts index cb96ff0c09a..d9116b70567 100644 --- a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts +++ b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts @@ -21,6 +21,7 @@ import { useLinkStore } from '@/stores/linkStore' import { graphScopeOf } from '@/types/graphScopeId' import { toLinkId } from '@/types/linkId' import { toNodeId } from '@/types/nodeId' +import type { LinkId } from '@/lib/litegraph/src/LLink' import type { NodeId } from '@/types/nodeId' const DEFINITION_ORDER = ['in_a', 'in_b', 'in_c'] @@ -47,6 +48,54 @@ class SourceNode extends LGraphNode { } } +/** + * Mirrors the two app behaviours FE-258 needs: `ComfyNode.configure` rewrites + * `data.inputs` into node-definition order and appends the serialized inputs + * the definition lacks, and a dynamic combo rebuilds its child inputs when its + * value is applied. Records the link on the child's slot at that moment. + */ +class GroupWidgetTargetNode extends LGraphNode { + static readonly DEFINITION_INPUTS = ['image', 'resize_type.width'] + childLinkIdOnValueApply?: LinkId + + constructor(title?: string) { + super(title ?? 'GroupWidgetTarget') + for (const name of GroupWidgetTargetNode.DEFINITION_INPUTS) + this.addInput(name, 'number') + const widget = this.addWidget( + 'combo', + 'resize_type', + 'scale dimensions', + () => {}, + { values: ['scale dimensions', 'scale by multiplier'] } + ) + let value = widget.value + Object.defineProperty(widget, 'value', { + get: () => value, + set: (next: string) => { + value = next + const slot = this.inputs.findIndex( + (input) => input.name === 'resize_type.multiplier' + ) + this.childLinkIdOnValueApply = this.getInputLink(slot)?.id + } + }) + } + + override configure(data: ISerialisedNode): void { + const serialized = data.inputs ?? [] + const defined = this.inputs.map( + (input) => serialized.find((entry) => entry.name === input.name) ?? input + ) + const definedNames = new Set(this.inputs.map((input) => input.name)) + data.inputs = [ + ...defined, + ...serialized.filter((entry) => !definedNames.has(entry.name)) + ] + super.configure(data) + } +} + const SUBGRAPH_ID = 'ab111111-1111-4111-8111-111111111111' function shiftedNodesAndLinks( @@ -830,7 +879,35 @@ describe('realignGroupWidgetChildLinks (FE-258)', () => { ).toBe(link.id) }) - it('leaves inputs that no group widget owns', () => { + it('moves an ordinary input link that holds a child destination slot', () => { + const { source, target } = groupWidgetSetup( + [ + 'image', + 'resize_type.width', + 'resize_type', + 'roll', + 'resize_type.multiplier' + ], + 'resize_type' + ) + const child = source.connect(0, target, 1)! + const ordinary = source.connect(0, target, 4)! + + realignGroupWidgetChildLinks(target, { + id: target.id, + inputs: serializedInputs(target, { + 'resize_type.multiplier': child.id, + roll: ordinary.id + }) + }) + + expect({ + child: child.target_slot, + ordinary: ordinary.target_slot + }).toEqual({ child: 4, ordinary: 3 }) + }) + + it('leaves a node that has no group widget child input', () => { const { source, target } = groupWidgetSetup( ['first', 'second', 'resize_type'], 'resize_type' @@ -845,24 +922,88 @@ describe('realignGroupWidgetChildLinks (FE-258)', () => { expect(link.target_slot).toBe(0) }) - it('leaves the children of a group nested inside a group widget', () => { + it('leaves the links of a group nested inside a group widget', () => { const { source, target } = groupWidgetSetup( [ 'model.reference_images.image_1', - 'other', - 'model.reference_images.mask' + 'model.generate_audio', + 'model.reference_images.image_2' ], 'model' ) - const link = source.connect(0, target, 1)! + const nested = source.connect(0, target, 0)! realignGroupWidgetChildLinks(target, { id: target.id, inputs: serializedInputs(target, { - 'model.reference_images.image_1': link.id + 'model.reference_images.image_2': nested.id }) }) - expect(link.target_slot).toBe(1) + expect(nested.target_slot).toBe(0) + }) +}) + +describe('LGraphNode.configure realignment ordering (FE-258)', () => { + beforeEach(() => { + LiteGraph.registerNodeType('test/RealignSource', SourceNode) + LiteGraph.registerNodeType('test/GroupWidgetTarget', GroupWidgetTargetNode) + }) + + it('realigns a child link before the group widget value is applied', () => { + const graph = new LGraph() + const workflow: SerialisableGraph = { + id: 'ab000000-0000-4000-8000-000000000004', + version: 1, + revision: 0, + state: { lastNodeId: 2, lastLinkId: 1, lastGroupId: 0, lastRerouteId: 0 }, + nodes: [ + { + id: 1, + type: 'test/RealignSource', + pos: [0, 0], + size: [140, 60], + flags: {}, + order: 0, + mode: 0, + inputs: [], + outputs: [{ name: 'out', type: 'number', links: [1] }], + properties: {} + }, + { + id: 2, + type: 'test/GroupWidgetTarget', + pos: [300, 0], + size: [140, 80], + flags: {}, + order: 1, + mode: 0, + inputs: [ + { name: 'image', type: 'number', link: null }, + { name: 'resize_type.multiplier', type: 'number', link: 1 } + ], + outputs: [], + properties: {}, + widgets_values: ['scale by multiplier'] + } + ], + links: [ + { + id: toLinkId(1), + origin_id: 1, + origin_slot: 0, + target_id: 2, + target_slot: 1, + type: 'number' + } + ] + } + graph.configure(workflow) + + const target = graph.getNodeById(toNodeId(2)) + expect(target).toBeInstanceOf(GroupWidgetTargetNode) + expect((target as GroupWidgetTargetNode).childLinkIdOnValueApply).toBe( + toLinkId(1) + ) }) }) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 42cabf75246..3217c5f28aa 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -177,39 +177,57 @@ export function detachSerialisedLinks( return linkByInputName } +function groupNameOf(inputName: string): string | undefined { + const separator = inputName ? inputName.lastIndexOf('.') : -1 + return separator < 1 ? undefined : inputName.slice(0, separator) +} + /** - * Whether `inputName` is a child input of a group widget on `node`. - * - * Group widgets (dynamic combos) name their child inputs - * `.` and replace the whole set whenever their own - * value changes. The group is the segment before the *last* dot, so inputs of - * a nested dynamic group — autogrow names its children - * `..` — resolve to their own group and are excluded. + * Whether a group widget on `node` owns `inputName`'s slot. Group widgets + * (dynamic combos) name their child inputs `.` and + * replace the whole set whenever their own value changes. */ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { - if (!inputName) return false + const groupName = groupNameOf(inputName) + if (groupName === undefined) return false - const separator = inputName.lastIndexOf('.') - if (separator < 1) return false - - const groupName = inputName.slice(0, separator) return node.widgets?.some((widget) => widget.name === groupName) ?? false } /** - * Realigns the links of a node's group widget child inputs, before the group - * widget's serialized value is applied. + * Whether a dynamic group that is not a widget owns `inputName`'s slot — + * autogrow names its children `..`, so their group is + * a nested input spec rather than a widget. + * + * Those groups grow and renumber their own slots while the graph configures, + * and realigning their links by name that early destroys them (see + * `browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts`, "loads + * with both reference images connected"). + */ +function isNestedDynamicGroupInput( + node: LGraphNode, + inputName: string +): boolean { + const groupName = groupNameOf(inputName) + return groupName !== undefined && !isGroupWidgetChildInput(node, inputName) +} + +/** + * Realigns a node's input links by name before its group widget values are + * applied, for nodes that have a group widget child input. * - * Applying that value rebuilds every child input of the group and hands each - * surviving link to the new input of the same name. A link sitting on the - * wrong slot — the node definition lays out the default option's children, - * while `target_slot` counts the serialized layout — is handed to an input - * that the selected option does not define, and is dropped. + * Applying a group widget's value rebuilds every child input of the group and + * hands each surviving link to the new input of the same name. A link sitting + * on the wrong slot — the node definition lays out the default option's + * children, while `target_slot` counts the serialized layout — is handed to an + * input that the selected option does not define, and is dropped. Through a + * subgraph boundary that demotes the promoted widget to a disconnected input + * slot. * - * Only group widget children are realigned: {@link LGraph.configure} runs the - * full pass once every node is configured, which is what lets it resolve - * contention for a slot between nodes. Realigning a node's other inputs here - * would claim slots from nodes that have not configured yet. + * The node's ordinary inputs join the batch so that a link still occupying a + * child's destination slot is moved in the same atomic update instead of + * blocking it. Links owned by a nested dynamic group are left to + * {@link LGraph.configure}'s final pass. */ export function realignGroupWidgetChildLinks( node: LGraphNode, @@ -218,10 +236,11 @@ export function realignGroupWidgetChildLinks( const { graph } = node if (!graph) return - const inputs = nodeData.inputs?.filter((input) => - isGroupWidgetChildInput(node, input.name) + const inputs = nodeData.inputs?.filter( + (input) => !isNestedDynamicGroupInput(node, input.name) ) - if (!inputs?.length) return + if (!inputs?.some((input) => isGroupWidgetChildInput(node, input.name))) + return realignInputLinkSlots(graph, [[node.id, { id: nodeData.id, inputs }]]) } From 48180d49ba4ab7558709864f3c719668cb2bf55c Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 11 Sep 2026 21:52:48 +0000 Subject: [PATCH 3/6] test(subgraph): cover the duplicate input FE-258 appends The fixture's host node now carries the legacy proxyWidgets property the real template has, which is what drives the duplicate `resize_type.multiplier_1` promotion, and the spec asserts the host's input names. Verified against main's sources: the widget assertion and the input-name assertion both fail. Also point LoadImage at example.png, the only image the test backend serves. --- .../subgraph-dynamic-combo-promoted-child.json | 6 ++++-- .../subgraphPromotedDynamicComboChild.spec.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json b/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json index d7293a2558b..ba7c8384343 100644 --- a/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json +++ b/browser_tests/assets/subgraphs/subgraph-dynamic-combo-promoted-child.json @@ -32,7 +32,7 @@ "ver": "0.27.0", "Node name for S&R": "LoadImage" }, - "widgets_values": ["watch_macro_shot.png", "image"] + "widgets_values": ["example.png", "image"] }, { "id": 66, @@ -68,7 +68,9 @@ "links": [2] } ], - "properties": {}, + "properties": { + "proxyWidgets": [["57", "resize_type.multiplier"]] + }, "widgets_values": [4] }, { diff --git a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts index 916fa9eb297..ee0539416a7 100644 --- a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts +++ b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts @@ -1,7 +1,17 @@ import { expect } from '@playwright/test' +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' import { getPromotedWidgetNames } from '@e2e/fixtures/utils/promotedWidgets' +import { toNodeId } from '@/types/nodeId' + +function getInputNames(comfyPage: ComfyPage, nodeId: string) { + return comfyPage.page.evaluate( + (id) => + window.app!.graph.getNodeById(id)?.inputs.map((input) => input.name), + toNodeId(nodeId) + ) +} // Reduced from the `utility_seedvr2_3b_int8_upscale_image` template (FE-258): // a `ResizeImageMaskNode` whose `resize_type` dynamic combo is set to a @@ -37,6 +47,10 @@ test.describe( await expect .poll(() => getPromotedWidgetNames(comfyPage, HOST_NODE_ID)) .toEqual([PROMOTED_INPUT_NAME]) + + await expect + .poll(() => getInputNames(comfyPage, HOST_NODE_ID)) + .toEqual(['image', PROMOTED_INPUT_NAME]) }) test('keeps the links of the nodes around it', async ({ comfyPage }) => { From 6663bd2ef35844ca539941b11dcbc362395d307e Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Tue, 22 Sep 2026 18:36:05 +0000 Subject: [PATCH 4/6] test: observe the FE-258 link through the real node definition path Replace the test double that mirrored `ComfyNode.configure` input normalization and the dynamic-combo value setter with a node registered through `registerNodeDef`. The regression is now observed as a surviving link on `resize_type.multiplier` after `LGraph.configure`, not as a recorded ordering artefact, so it cannot stay green if either real owner changes. It lives in `dynamicWidgets.test.ts` to keep `src/lib/` from importing the service layer. In the browser spec, drop the renderer setting hook and both explicit `waitForNodes()` calls that the `@vue-nodes` tag and `loadWorkflow()` already cover, reuse the shared `getInputNames` helper, and arrange the workflow load once in `beforeEach`. --- .../subgraphPromotedDynamicComboChild.spec.ts | 39 ++---- src/core/graph/widgets/dynamicWidgets.test.ts | 129 ++++++++++++++++++ .../src/LGraph.inputSlotRealign.test.ts | 113 --------------- 3 files changed, 139 insertions(+), 142 deletions(-) diff --git a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts index ee0539416a7..a02072ecd8c 100644 --- a/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts +++ b/browser_tests/tests/subgraph/subgraphPromotedDynamicComboChild.spec.ts @@ -1,43 +1,27 @@ import { expect } from '@playwright/test' -import type { ComfyPage } from '@e2e/fixtures/ComfyPage' import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' +import { getInputNames } from '@e2e/fixtures/utils/nodeInputLinks' import { getPromotedWidgetNames } from '@e2e/fixtures/utils/promotedWidgets' -import { toNodeId } from '@/types/nodeId' - -function getInputNames(comfyPage: ComfyPage, nodeId: string) { - return comfyPage.page.evaluate( - (id) => - window.app!.graph.getNodeById(id)?.inputs.map((input) => input.name), - toNodeId(nodeId) - ) -} // Reduced from the `utility_seedvr2_3b_int8_upscale_image` template (FE-258): // a `ResizeImageMaskNode` whose `resize_type` dynamic combo is set to a // non-default option, with that option's `multiplier` child widget promoted // through the subgraph boundary. -const WORKFLOW = 'subgraphs/subgraph-dynamic-combo-promoted-child' -const HOST_NODE_TITLE = 'Resize Image Subgraph' -const HOST_NODE_ID = '66' -const PROMOTED_WIDGET_LABEL = 'scale_multiplier' -const PROMOTED_INPUT_NAME = 'resize_type.multiplier' - test.describe( 'Promoted dynamic combo child widget', { tag: ['@subgraph', '@widget', '@vue-nodes'] }, () => { test.beforeEach(async ({ comfyPage }) => { - await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true) + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-dynamic-combo-promoted-child' + ) }) test('survives a workflow load', async ({ comfyPage }) => { - await comfyPage.workflow.loadWorkflow(WORKFLOW) - await comfyPage.vueNodes.waitForNodes() - const multiplier = comfyPage.vueNodes.getWidgetRowByLabel( - HOST_NODE_TITLE, - PROMOTED_WIDGET_LABEL + 'Resize Image Subgraph', + 'scale_multiplier' ) await expect(multiplier).toBeVisible() await expect( @@ -45,18 +29,15 @@ test.describe( ).toHaveValue('4.00') await expect - .poll(() => getPromotedWidgetNames(comfyPage, HOST_NODE_ID)) - .toEqual([PROMOTED_INPUT_NAME]) + .poll(() => getPromotedWidgetNames(comfyPage, '66')) + .toEqual(['resize_type.multiplier']) await expect - .poll(() => getInputNames(comfyPage, HOST_NODE_ID)) - .toEqual(['image', PROMOTED_INPUT_NAME]) + .poll(() => getInputNames(comfyPage, '66', '')) + .toEqual(['image', 'resize_type.multiplier']) }) test('keeps the links of the nodes around it', async ({ comfyPage }) => { - await comfyPage.workflow.loadWorkflow(WORKFLOW) - await comfyPage.vueNodes.waitForNodes() - await expect .poll(() => comfyPage.page.evaluate(() => diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 9003eb7c5e0..e7926aab95a 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -13,8 +13,12 @@ import { addDynamicCombo } from '@/core/graph/widgets/__fixtures__/dynamicInputHelpers' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { SerialisableGraph } from '@/lib/litegraph/src/types/serialisation' +import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema' import { useLitegraphService } from '@/services/litegraphService' import { useLinkStore } from '@/stores/linkStore' +import { toLinkId } from '@/types/linkId' +import { toNodeId } from '@/types/nodeId' const originalNamedValuesRestore = LiteGraph.namedValuesRestore afterEach(() => { @@ -623,3 +627,128 @@ describe('Autogrow', () => { } }) }) + +const RESIZE_NODE_TYPE = 'test/ResizeImageMask' +const SOURCE_NODE_TYPE = 'test/MultiplierSource' + +class SourceNode extends LGraphNode { + constructor(title?: string) { + super(title ?? 'Source') + this.addOutput('out', 'FLOAT') + } +} + +/** + * A reduced `ResizeImageMaskNode` (FE-258): a dynamic combo whose default + * option lays out a `width` child, and whose other option lays out a + * `multiplier` child instead. + */ +const resizeNodeDef: ComfyNodeDefV1 = { + name: RESIZE_NODE_TYPE, + display_name: 'Resize Image Mask', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + image: ['IMAGE', {}], + resize_type: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'scale dimensions', + inputs: { required: { width: ['INT', {}] } } + }, + { + key: 'scale by multiplier', + inputs: { required: { multiplier: ['FLOAT', {}] } } + } + ] + } + ] + } + }, + output: ['IMAGE'], + output_name: ['resized'], + output_node: false +} + +/** + * The node saved on `scale by multiplier`, so its serialized inputs carry + * `resize_type.multiplier` — a child the node definition does not lay out — + * on the slot the definition gives to `resize_type.width`. + */ +function savedDynamicComboChildWorkflow(): SerialisableGraph { + return { + id: 'ab000000-0000-4000-8000-00000000f258', + version: 1, + revision: 0, + state: { lastNodeId: 2, lastLinkId: 1, lastGroupId: 0, lastRerouteId: 0 }, + nodes: [ + { + id: 1, + type: SOURCE_NODE_TYPE, + pos: [0, 0], + size: [140, 60], + flags: {}, + order: 0, + mode: 0, + inputs: [], + outputs: [{ name: 'out', type: 'FLOAT', links: [1] }], + properties: {} + }, + { + id: 2, + type: RESIZE_NODE_TYPE, + pos: [300, 0], + size: [200, 120], + flags: {}, + order: 1, + mode: 0, + inputs: [ + { name: 'image', type: 'IMAGE', link: null }, + { name: 'resize_type.multiplier', type: 'FLOAT', link: 1 } + ], + outputs: [{ name: 'resized', type: 'IMAGE', links: [] }], + properties: {}, + widgets_values: ['scale by multiplier', 4] + } + ], + links: [ + { + id: toLinkId(1), + origin_id: 1, + origin_slot: 0, + target_id: 2, + target_slot: 1, + type: 'FLOAT' + } + ] + } +} + +describe('Dynamic combo child links on workflow load (FE-258)', () => { + beforeEach(async () => { + LiteGraph.registerNodeType(SOURCE_NODE_TYPE, SourceNode) + await useLitegraphService().registerNodeDef(RESIZE_NODE_TYPE, resizeNodeDef) + }) + + test('keeps the link on the child the selected option lays out', () => { + const graph = new LGraph() + graph.configure(savedDynamicComboChildWorkflow()) + + const target = graph.getNodeById(toNodeId(2)) + assert.ok(target, 'configured target node') + const multiplierSlot = target.inputs.findIndex( + (input) => input.name === 'resize_type.multiplier' + ) + expect({ + inputNames: target.inputs.map((input) => input.name), + multiplierLinkId: target.getInputLink(multiplierSlot)?.id + }).toEqual({ + inputNames: ['image', 'resize_type', 'resize_type.multiplier'], + multiplierLinkId: toLinkId(1) + }) + }) +}) diff --git a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts index d9116b70567..38fc98d4bc0 100644 --- a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts +++ b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts @@ -21,7 +21,6 @@ import { useLinkStore } from '@/stores/linkStore' import { graphScopeOf } from '@/types/graphScopeId' import { toLinkId } from '@/types/linkId' import { toNodeId } from '@/types/nodeId' -import type { LinkId } from '@/lib/litegraph/src/LLink' import type { NodeId } from '@/types/nodeId' const DEFINITION_ORDER = ['in_a', 'in_b', 'in_c'] @@ -48,54 +47,6 @@ class SourceNode extends LGraphNode { } } -/** - * Mirrors the two app behaviours FE-258 needs: `ComfyNode.configure` rewrites - * `data.inputs` into node-definition order and appends the serialized inputs - * the definition lacks, and a dynamic combo rebuilds its child inputs when its - * value is applied. Records the link on the child's slot at that moment. - */ -class GroupWidgetTargetNode extends LGraphNode { - static readonly DEFINITION_INPUTS = ['image', 'resize_type.width'] - childLinkIdOnValueApply?: LinkId - - constructor(title?: string) { - super(title ?? 'GroupWidgetTarget') - for (const name of GroupWidgetTargetNode.DEFINITION_INPUTS) - this.addInput(name, 'number') - const widget = this.addWidget( - 'combo', - 'resize_type', - 'scale dimensions', - () => {}, - { values: ['scale dimensions', 'scale by multiplier'] } - ) - let value = widget.value - Object.defineProperty(widget, 'value', { - get: () => value, - set: (next: string) => { - value = next - const slot = this.inputs.findIndex( - (input) => input.name === 'resize_type.multiplier' - ) - this.childLinkIdOnValueApply = this.getInputLink(slot)?.id - } - }) - } - - override configure(data: ISerialisedNode): void { - const serialized = data.inputs ?? [] - const defined = this.inputs.map( - (input) => serialized.find((entry) => entry.name === input.name) ?? input - ) - const definedNames = new Set(this.inputs.map((input) => input.name)) - data.inputs = [ - ...defined, - ...serialized.filter((entry) => !definedNames.has(entry.name)) - ] - super.configure(data) - } -} - const SUBGRAPH_ID = 'ab111111-1111-4111-8111-111111111111' function shiftedNodesAndLinks( @@ -943,67 +894,3 @@ describe('realignGroupWidgetChildLinks (FE-258)', () => { expect(nested.target_slot).toBe(0) }) }) - -describe('LGraphNode.configure realignment ordering (FE-258)', () => { - beforeEach(() => { - LiteGraph.registerNodeType('test/RealignSource', SourceNode) - LiteGraph.registerNodeType('test/GroupWidgetTarget', GroupWidgetTargetNode) - }) - - it('realigns a child link before the group widget value is applied', () => { - const graph = new LGraph() - const workflow: SerialisableGraph = { - id: 'ab000000-0000-4000-8000-000000000004', - version: 1, - revision: 0, - state: { lastNodeId: 2, lastLinkId: 1, lastGroupId: 0, lastRerouteId: 0 }, - nodes: [ - { - id: 1, - type: 'test/RealignSource', - pos: [0, 0], - size: [140, 60], - flags: {}, - order: 0, - mode: 0, - inputs: [], - outputs: [{ name: 'out', type: 'number', links: [1] }], - properties: {} - }, - { - id: 2, - type: 'test/GroupWidgetTarget', - pos: [300, 0], - size: [140, 80], - flags: {}, - order: 1, - mode: 0, - inputs: [ - { name: 'image', type: 'number', link: null }, - { name: 'resize_type.multiplier', type: 'number', link: 1 } - ], - outputs: [], - properties: {}, - widgets_values: ['scale by multiplier'] - } - ], - links: [ - { - id: toLinkId(1), - origin_id: 1, - origin_slot: 0, - target_id: 2, - target_slot: 1, - type: 'number' - } - ] - } - graph.configure(workflow) - - const target = graph.getNodeById(toNodeId(2)) - expect(target).toBeInstanceOf(GroupWidgetTargetNode) - expect((target as GroupWidgetTargetNode).childLinkIdOnValueApply).toBe( - toLinkId(1) - ) - }) -}) From 569e8ca4b36274cb8ca8a7cac1889088ab720d21 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Tue, 22 Sep 2026 21:11:18 +0000 Subject: [PATCH 5/6] fix(litegraph): own autogrow exclusion by group registry, not dotted names `INodeInputSlot.name` is an arbitrary string, so the dotted-name heuristic excluded ordinary inputs such as `metadata.scale` from the early realignment. An excluded link still occupies its slot, so when it sat on a group widget child's destination the atomic update was rejected, the child stayed on the stale slot, and the rebuild dropped it. Read ownership from the registry `applyAutogrow` populates instead, which is the key autogrow's own connection handler resolves a group by. Preserving that ordinary child link then exposed a stale-slot bug in the dynamic combo rebuild: `replaceNodeInputs` numbers every replacement before any callback runs, so once an earlier callback grows an autogrow group the later callbacks report slots that have since shifted. Autogrow reads the slot rather than the input it is handed, so it grew a second trailing slot on every load of a node whose combo option places an autogrow group before an ordinary child (the `OpenAIGPTImageNodeV2` shape). Resolve each replacement's slot from its input when its callback fires. --- src/core/graph/widgets/dynamicWidgets.test.ts | 177 ++++++++++++++++++ src/core/graph/widgets/dynamicWidgets.ts | 6 +- .../src/LGraph.inputSlotRealign.test.ts | 41 ++-- src/lib/litegraph/src/linkDeduplication.ts | 41 ++-- 4 files changed, 233 insertions(+), 32 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index e7926aab95a..1da3ee989d2 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -13,6 +13,7 @@ import { addDynamicCombo } from '@/core/graph/widgets/__fixtures__/dynamicInputHelpers' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import { realignGroupWidgetChildLinks } from '@/lib/litegraph/src/linkDeduplication' import type { SerialisableGraph } from '@/lib/litegraph/src/types/serialisation' import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema' import { useLitegraphService } from '@/services/litegraphService' @@ -752,3 +753,179 @@ describe('Dynamic combo child links on workflow load (FE-258)', () => { }) }) }) + +const REFERENCE_NODE_TYPE = 'test/AutogrowInsideCombo' + +/** + * Shaped after `ByteDance2ReferenceNode`: a dynamic combo whose option holds + * both an ordinary child widget and an autogrow group, so the group's children + * are named `model.reference_images.` and its registry key is + * `model.reference_images`. + */ +const referenceNodeDef: ComfyNodeDefV1 = { + name: REFERENCE_NODE_TYPE, + display_name: 'Autogrow Inside Combo', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'Seedance', + inputs: { + required: { + generate_audio: ['BOOLEAN', { default: true }], + reference_images: [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { + required: { reference_image: ['IMAGE', {}] } + }, + names: ['image_1', 'image_2', 'image_3'], + min: 2 + } + } + ] + } + } + } + ] + } + ] + } + }, + output: ['VIDEO'], + output_name: ['VIDEO'], + output_node: false +} + +describe('Autogrow nested inside a group widget (FE-258)', () => { + beforeEach(async () => { + await useLitegraphService().registerNodeDef( + REFERENCE_NODE_TYPE, + referenceNodeDef + ) + }) + + test('leaves an autogrow child link where the group put it', () => { + const graph = new LGraph() + const node = LiteGraph.createNode(REFERENCE_NODE_TYPE) + assert.ok(node, 'reference node') + graph.add(node) + const slotOf = (name: string) => + node.inputs.findIndex((input) => input.name === name) + const connectedSlot = slotOf('model.reference_images.image_1') + const nested = connectInput(node, connectedSlot, graph) + + realignGroupWidgetChildLinks(node, { + id: node.id, + inputs: node.inputs.map((input) => ({ + name: input.name, + type: String(input.type), + link: input.name === 'model.reference_images.image_3' ? nested.id : null + })) + }) + + expect(nested.target_slot).toBe(connectedSlot) + }) +}) + +const GROWN_NODE_TYPE = 'test/AutogrowBeforeOrdinaryChild' + +/** + * Shaped after `OpenAIGPTImageNodeV2`: a dynamic combo option whose autogrow + * group is followed by an ordinary child input. Reloading such a node replays + * both links, and the group grows a slot while doing so. + */ +const grownNodeDef: ComfyNodeDefV1 = { + name: GROWN_NODE_TYPE, + display_name: 'Autogrow Before Ordinary Child', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'gpt-image-1', + inputs: { + required: { + seed: ['INT', { default: 0 }], + images: [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { required: { image: ['IMAGE', {}] } }, + names: ['image_1', 'image_2', 'image_3', 'image_4'], + min: 0 + } + } + ], + mask: ['MASK', { forceInput: true }] + } + } + } + ] + } + ] + } + }, + output: ['IMAGE'], + output_name: ['IMAGE'], + output_node: false +} + +class ImageMaskSourceNode extends LGraphNode { + constructor(title?: string) { + super(title ?? 'ImageMaskSource') + this.addOutput('image', 'IMAGE') + this.addOutput('mask', 'MASK') + } +} + +describe('Autogrow followed by an ordinary combo child (FE-258)', () => { + beforeEach(async () => { + LiteGraph.registerNodeType('test/ImageMaskSource', ImageMaskSourceNode) + await useLitegraphService().registerNodeDef(GROWN_NODE_TYPE, grownNodeDef) + }) + + test('keeps the autogrow slot count across a load', () => { + const graph = new LGraph() + const source = new ImageMaskSourceNode() + graph.add(source) + const node = LiteGraph.createNode(GROWN_NODE_TYPE) + assert.ok(node, 'gpt image like node') + graph.add(node) + const slotOf = (name: string) => + node.inputs.findIndex((input) => input.name === name) + source.connect(0, node, slotOf('model.images.image_1')) + source.connect(1, node, slotOf('model.mask')) + const inputNames = (target: LGraphNode) => + target.inputs.map( + (input, slot) => `${input.name}${target.getInputLink(slot) ? '*' : ''}` + ) + const before = inputNames(node).filter((name) => + name.startsWith('model.images.') + ) + + const reloaded = new LGraph() + reloaded.configure(structuredClone(graph.serialize())) + + const reloadedNode = reloaded.getNodeById(node.id) + assert.ok(reloadedNode, 'reloaded node') + expect({ + images: inputNames(reloadedNode).filter((name) => + name.startsWith('model.images.') + ), + maskConnected: inputNames(reloadedNode).includes('model.mask*') + }).toEqual({ images: before, maskConnected: true }) + }) +}) diff --git a/src/core/graph/widgets/dynamicWidgets.ts b/src/core/graph/widgets/dynamicWidgets.ts index ba35b31426a..ff11231369a 100644 --- a/src/core/graph/widgets/dynamicWidgets.ts +++ b/src/core/graph/widgets/dynamicWidgets.ts @@ -243,7 +243,11 @@ function dynamicComboWidget( } const result = commitMutatedInputs(node, previous, inputLinks) if (!result.ok) return - for (const { input, link, slot } of result.replacements) { + //A callback can grow the group it lands on, shifting every input after + //it, so the slot captured before the batch is stale for later entries. + for (const { input, link } of result.replacements) { + const slot = node.inputs.indexOf(input) + if (slot === -1) continue node.onConnectionsChange?.(LiteGraph.INPUT, slot, true, link, input) } restoreRemovedValues(value, addedWidgetNames) diff --git a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts index 38fc98d4bc0..26e78fefb25 100644 --- a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts +++ b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts @@ -858,39 +858,46 @@ describe('realignGroupWidgetChildLinks (FE-258)', () => { }).toEqual({ child: 4, ordinary: 3 }) }) - it('leaves a node that has no group widget child input', () => { + it('moves a dotted ordinary input link that holds a child destination slot', () => { const { source, target } = groupWidgetSetup( - ['first', 'second', 'resize_type'], + [ + 'image', + 'resize_type.width', + 'resize_type', + 'metadata.scale', + 'resize_type.multiplier' + ], 'resize_type' ) - const link = source.connect(0, target, 0)! + const child = source.connect(0, target, 1)! + const ordinary = source.connect(0, target, 4)! realignGroupWidgetChildLinks(target, { id: target.id, - inputs: serializedInputs(target, { second: link.id }) + inputs: serializedInputs(target, { + 'resize_type.multiplier': child.id, + 'metadata.scale': ordinary.id + }) }) - expect(link.target_slot).toBe(0) + expect({ + child: child.target_slot, + ordinary: ordinary.target_slot + }).toEqual({ child: 4, ordinary: 3 }) }) - it('leaves the links of a group nested inside a group widget', () => { + it('leaves a node that has no group widget child input', () => { const { source, target } = groupWidgetSetup( - [ - 'model.reference_images.image_1', - 'model.generate_audio', - 'model.reference_images.image_2' - ], - 'model' + ['first', 'second', 'resize_type'], + 'resize_type' ) - const nested = source.connect(0, target, 0)! + const link = source.connect(0, target, 0)! realignGroupWidgetChildLinks(target, { id: target.id, - inputs: serializedInputs(target, { - 'model.reference_images.image_2': nested.id - }) + inputs: serializedInputs(target, { second: link.id }) }) - expect(nested.target_slot).toBe(0) + expect(link.target_slot).toBe(0) }) }) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 3217c5f28aa..be0359220f7 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -195,21 +195,34 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { } /** - * Whether a dynamic group that is not a widget owns `inputName`'s slot — - * autogrow names its children `..`, so their group is - * a nested input spec rather than a widget. + * Whether a registered autogrow group owns `inputName`'s slot. * - * Those groups grow and renumber their own slots while the graph configures, - * and realigning their links by name that early destroys them (see - * `browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts`, "loads - * with both reference images connected"). + * Autogrow groups grow and renumber their own slots while the graph + * configures, and realigning their links by name that early destroys them + * (see `browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts`, + * "loads with both reference images connected"). + * + * Ownership comes from the registry `applyAutogrow` populates, under the same + * key autogrow's own connection handler resolves a slot's group by. A group + * is not a widget, so there is no widget name to match a prefix against as + * {@link isGroupWidgetChildInput} does, and the dotted name alone will not + * serve: `INodeInputSlot.name` is an arbitrary string, so an ordinary input + * may be dotted without belonging to any group. + * + * The registry only covers groups the selected option laid out. Children of + * an option that is not selected still reach this filter, because + * `ComfyNode.configure` appends every serialized input the definition lacks. + * Realigning those is harmless: their group's handler bails on the same + * missing key, so nothing renumbers behind the move. */ -function isNestedDynamicGroupInput( - node: LGraphNode, - inputName: string -): boolean { +function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) - return groupName !== undefined && !isGroupWidgetChildInput(node, inputName) + if (groupName === undefined) return false + + const autogrowGroups = node.comfyDynamic?.autogrow + return ( + autogrowGroups !== undefined && Object.hasOwn(autogrowGroups, groupName) + ) } /** @@ -226,7 +239,7 @@ function isNestedDynamicGroupInput( * * The node's ordinary inputs join the batch so that a link still occupying a * child's destination slot is moved in the same atomic update instead of - * blocking it. Links owned by a nested dynamic group are left to + * blocking it. Links owned by an autogrow group are left to * {@link LGraph.configure}'s final pass. */ export function realignGroupWidgetChildLinks( @@ -237,7 +250,7 @@ export function realignGroupWidgetChildLinks( if (!graph) return const inputs = nodeData.inputs?.filter( - (input) => !isNestedDynamicGroupInput(node, input.name) + (input) => !isAutogrowGroupInput(node, input.name) ) if (!inputs?.some((input) => isGroupWidgetChildInput(node, input.name))) return From 8ed2a63306fec7d7b4556aebc81aa25815110d7b Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 23 Sep 2026 04:18:25 +0000 Subject: [PATCH 6/6] test: table-drive the ordinary-input realign cases --- .../src/LGraph.inputSlotRealign.test.ts | 84 +++++++------------ 1 file changed, 31 insertions(+), 53 deletions(-) diff --git a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts index 26e78fefb25..dfdb82967d7 100644 --- a/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts +++ b/src/lib/litegraph/src/LGraph.inputSlotRealign.test.ts @@ -830,61 +830,39 @@ describe('realignGroupWidgetChildLinks (FE-258)', () => { ).toBe(link.id) }) - it('moves an ordinary input link that holds a child destination slot', () => { - const { source, target } = groupWidgetSetup( - [ - 'image', - 'resize_type.width', - 'resize_type', - 'roll', - 'resize_type.multiplier' - ], - 'resize_type' - ) - const child = source.connect(0, target, 1)! - const ordinary = source.connect(0, target, 4)! - - realignGroupWidgetChildLinks(target, { - id: target.id, - inputs: serializedInputs(target, { - 'resize_type.multiplier': child.id, - roll: ordinary.id - }) - }) - - expect({ - child: child.target_slot, - ordinary: ordinary.target_slot - }).toEqual({ child: 4, ordinary: 3 }) - }) - - it('moves a dotted ordinary input link that holds a child destination slot', () => { - const { source, target } = groupWidgetSetup( - [ - 'image', - 'resize_type.width', - 'resize_type', - 'metadata.scale', - 'resize_type.multiplier' - ], - 'resize_type' - ) - const child = source.connect(0, target, 1)! - const ordinary = source.connect(0, target, 4)! - - realignGroupWidgetChildLinks(target, { - id: target.id, - inputs: serializedInputs(target, { - 'resize_type.multiplier': child.id, - 'metadata.scale': ordinary.id + it.for([ + { label: 'a plain ordinary', ordinaryName: 'roll' }, + { label: 'a dotted ordinary', ordinaryName: 'metadata.scale' } + ])( + 'moves $label input link that holds a child destination slot', + ({ ordinaryName }) => { + const { source, target } = groupWidgetSetup( + [ + 'image', + 'resize_type.width', + 'resize_type', + ordinaryName, + 'resize_type.multiplier' + ], + 'resize_type' + ) + const child = source.connect(0, target, 1)! + const ordinary = source.connect(0, target, 4)! + + realignGroupWidgetChildLinks(target, { + id: target.id, + inputs: serializedInputs(target, { + 'resize_type.multiplier': child.id, + [ordinaryName]: ordinary.id + }) }) - }) - expect({ - child: child.target_slot, - ordinary: ordinary.target_slot - }).toEqual({ child: 4, ordinary: 3 }) - }) + expect({ + child: child.target_slot, + ordinary: ordinary.target_slot + }).toEqual({ child: 4, ordinary: 3 }) + } + ) it('leaves a node that has no group widget child input', () => { const { source, target } = groupWidgetSetup(