From 0bd2d4d673b75cbdd9ae54c845441eb99c5f64b5 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Fri, 30 Oct 2026 22:30:07 +0900 Subject: [PATCH 1/6] test: cover the image crop preview after reopening a dynamic-input node --- .../widgets/image_crop_dynamic_inputs.json | 148 ++++++++++++++++++ .../widgets/imageCropDynamicInputs.spec.ts | 75 +++++++++ src/composables/useImageCrop.test.ts | 31 +++- 3 files changed, 247 insertions(+), 7 deletions(-) create mode 100644 browser_tests/assets/widgets/image_crop_dynamic_inputs.json create mode 100644 browser_tests/tests/vueNodes/widgets/imageCropDynamicInputs.spec.ts diff --git a/browser_tests/assets/widgets/image_crop_dynamic_inputs.json b/browser_tests/assets/widgets/image_crop_dynamic_inputs.json new file mode 100644 index 00000000000..15c34e01cb0 --- /dev/null +++ b/browser_tests/assets/widgets/image_crop_dynamic_inputs.json @@ -0,0 +1,148 @@ +{ + "id": "dadf4878-8f8f-41bc-bf4a-53714aaeede1", + "revision": 0, + "last_node_id": 2, + "last_link_id": 1, + "nodes": [ + { + "id": 1, + "type": "LoadImage", + "pos": [50, 80], + "size": [282.798828125, 102], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "image", + "name": "image", + "type": "COMBO", + "widget": { + "name": "image" + }, + "link": null + }, + { + "localized_name": "choose file to upload", + "name": "upload", + "type": "IMAGEUPLOAD", + "widget": { + "name": "upload" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "IMAGE", + "name": "IMAGE", + "type": "IMAGE", + "links": [1] + }, + { + "localized_name": "MASK", + "name": "MASK", + "type": "MASK", + "links": null + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": ["example.png", "image"], + "widgets_values_named": { + "image": "example.png", + "upload": "image" + } + }, + { + "id": 2, + "type": "DynamicInputImageCrop", + "pos": [450, 80], + "size": [400, 500], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "image_1", + "name": "model.images.image_1", + "type": "IMAGE", + "link": 1 + }, + { + "localized_name": "image_2", + "name": "model.images.image_2", + "shape": 7, + "type": "IMAGE", + "link": null + }, + { + "localized_name": "region", + "name": "model.region", + "type": "BOUNDING_BOX", + "widget": { + "name": "model.region" + }, + "link": null + }, + { + "localized_name": "model", + "name": "model", + "type": "COMFY_DYNAMICCOMBO_V3", + "widget": { + "name": "model" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "IMAGE", + "name": "IMAGE", + "type": "IMAGE", + "links": null + } + ], + "properties": { + "Node name for S&R": "DynamicInputImageCrop" + }, + "widgets_values": [ + "Crop", + { + "x": 0, + "y": 0, + "width": 512, + "height": 512 + }, + 0, + 0, + 512, + 512 + ], + "widgets_values_named": { + "model": "Crop", + "model.region": { + "x": 0, + "y": 0, + "width": 512, + "height": 512 + }, + "x": 0, + "y": 0, + "width": 512, + "height": 512 + } + } + ], + "links": [[1, 1, 0, 2, 0, "IMAGE"]], + "groups": [], + "config": {}, + "extra": { + "ds": { + "scale": 1, + "offset": [0, 0] + } + }, + "version": 0.4 +} diff --git a/browser_tests/tests/vueNodes/widgets/imageCropDynamicInputs.spec.ts b/browser_tests/tests/vueNodes/widgets/imageCropDynamicInputs.spec.ts new file mode 100644 index 00000000000..7e4835c7af3 --- /dev/null +++ b/browser_tests/tests/vueNodes/widgets/imageCropDynamicInputs.spec.ts @@ -0,0 +1,75 @@ +import { + comfyExpect as expect, + comfyPageFixture +} from '@e2e/fixtures/ComfyPage' +import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' + +const test = comfyPageFixture.extend({ + page: async ({ page }, use) => { + await page.route('**/object_info', async (route) => { + const response = await route.fetch() + const definitions: Record = await response.json() + const cropNode: ComfyNodeDef = { + name: 'DynamicInputImageCrop', + display_name: 'Dynamic Input Image Crop', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'Crop', + inputs: { + required: { + images: [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { required: { image: ['IMAGE', {}] } }, + names: ['image_1', 'image_2'], + min: 1 + } + } + ], + region: ['BOUNDING_BOX', { component: 'ImageCrop' }] + } + } + } + ] + } + ] + } + }, + output: ['IMAGE'], + output_name: ['IMAGE'], + output_node: false + } + await route.fulfill({ + response, + json: { ...definitions, [cropNode.name]: cropNode } + }) + }) + await use(page) + } +}) + +test.describe( + 'Image Crop with dynamic inputs', + { tag: ['@widget', '@vue-nodes'] }, + () => { + test('shows the connected image after reopening a dynamic-input crop node', async ({ + comfyPage + }) => { + await comfyPage.workflow.loadWorkflow('widgets/image_crop_dynamic_inputs') + + const cropNode = comfyPage.vueNodes.getNodeLocator('2') + await expect(cropNode).toBeVisible() + await expect.soft(cropNode.getByTestId('crop-overlay')).toBeVisible() + await expect.soft(cropNode.getByTestId('crop-empty-state')).toBeHidden() + }) + } +) diff --git a/src/composables/useImageCrop.test.ts b/src/composables/useImageCrop.test.ts index 3ce672d1292..efe15156be4 100644 --- a/src/composables/useImageCrop.test.ts +++ b/src/composables/useImageCrop.test.ts @@ -240,6 +240,7 @@ describe('useImageCrop', () => { }) cropNode = createMockLGraphNode({ id: 2, + inputs: [{ name: 'image', type: 'IMAGE' }], getInputNode: vi.fn(() => sourceNode), getInputLink: vi.fn(() => ({ origin_slot: 0 })), isSubgraphNode: () => false @@ -283,14 +284,11 @@ describe('useImageCrop', () => { }) } - /** - * Resolves the image input through the link store, the way - * `LGraphNode.getInputLink` does, so link edits drive the preview. - */ - function useLinkedCropNode() { + function useLinkedCropNode(inputs = [{ name: 'image', type: 'IMAGE' }]) { const linkStore = useLinkStore() cropNode = createMockLGraphNode({ id: CROP_NODE_ID, + inputs, isSubgraphNode: () => false, getInputLink: (slot: number) => linkStore.getInputSlotLink(GRAPH_SCOPE, CROP_NODE_ID, slot) ?? null, @@ -302,14 +300,14 @@ describe('useImageCrop', () => { mockResolveNode.mockReturnValue(cropNode) } - function connectImageInput() { + function connectImageInput(targetSlot = 0) { useLinkStore().registerLink(GRAPH_SCOPE, { id: toLinkId(1), graphId: GRAPH_SCOPE.owningGraphId, originNodeId: toNodeId(99), originSlot: 0, targetNodeId: CROP_NODE_ID, - targetSlot: 0, + targetSlot, type: 'IMAGE' }) } @@ -336,6 +334,7 @@ describe('useImageCrop', () => { it('returns null image URL when there is no input node', async () => { const alone = createMockLGraphNode({ id: 2, + inputs: [{ name: 'image', type: 'IMAGE' }], getInputNode: vi.fn(() => null), getInputLink: vi.fn(), isSubgraphNode: () => false @@ -352,6 +351,7 @@ describe('useImageCrop', () => { }) const sgCrop = createMockLGraphNode({ id: 2, + inputs: [{ name: 'image', type: 'IMAGE' }], getInputNode: vi.fn(() => subgraphInput), getInputLink: vi.fn(() => null), isSubgraphNode: () => false @@ -373,6 +373,7 @@ describe('useImageCrop', () => { const sgCrop = createMockLGraphNode({ id: 2, + inputs: [{ name: 'image', type: 'IMAGE' }], getInputNode: vi.fn(() => subgraphInput), getInputLink: vi.fn(() => ({ origin_slot: 0 })), isSubgraphNode: () => false @@ -420,6 +421,7 @@ describe('useImageCrop', () => { mockResolveNode.mockReturnValue( createMockLGraphNode({ id: 2, + inputs: [{ name: 'image', type: 'IMAGE' }], getInputNode: vi.fn(() => reloadedSource), getInputLink: vi.fn(() => ({ origin_slot: 0 })), isSubgraphNode: () => false @@ -446,6 +448,20 @@ describe('useImageCrop', () => { expect(vm.imageUrl).toBe('https://example.com/a.png') }) + it('shows the upstream image when the image input is not the first input, as after reopening a dynamic-input node', async () => { + useLinkedCropNode([ + { name: 'model', type: 'COMFY_DYNAMICCOMBO_V3' }, + { name: 'model.images.image_1', type: 'IMAGE' }, + { name: 'model.images.image_2', type: 'IMAGE' }, + { name: 'model.region', type: 'BOUNDING_BOX' } + ]) + connectImageInput(1) + + const vm = await mountHarness() + + expect(vm.imageUrl).toBe('https://example.com/a.png') + }) + it('clears the preview when the image input is disconnected', async () => { useLinkedCropNode() connectImageInput() @@ -790,6 +806,7 @@ describe('WidgetImageCrop', () => { const source = createMockLGraphNode({ id: 99, isSubgraphNode: () => false }) const crop = createMockLGraphNode({ id: 2, + inputs: [{ name: 'image', type: 'IMAGE' }], getInputNode: vi.fn(() => source), getInputLink: vi.fn(), isSubgraphNode: () => false From 6e8229aa348380bfb50c75dcaf4ee1047efbacaa Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Fri, 30 Oct 2026 22:51:51 +0900 Subject: [PATCH 2/6] fix: find the Image Crop source by input type instead of slot 0 --- src/composables/useImageCrop.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/composables/useImageCrop.ts b/src/composables/useImageCrop.ts index 45beee1beda..aea8070d1de 100644 --- a/src/composables/useImageCrop.ts +++ b/src/composables/useImageCrop.ts @@ -37,8 +37,6 @@ const CORNER_DOT_CLASS = /** Minimum crop width/height in source image pixel space. */ const MIN_CROP_SIZE = 16 const CROP_BOX_BORDER = 1 -/** Slot the cropped image arrives on. */ -const IMAGE_INPUT_SLOT = 0 /** * Next `isLoading` when `imageUrl` transitions. `null` means do not change @@ -189,7 +187,12 @@ export function useImageCrop(nodeId: NodeId, options: UseImageCropOptions) { const cropNode = node.value if (!cropNode) return null - const sourceNode = resolveInputSourceNode(cropNode, IMAGE_INPUT_SLOT) + const imageInputSlot = cropNode.inputs.findIndex( + (input) => input.type === 'IMAGE' + ) + if (imageInputSlot === -1) return null + + const sourceNode = resolveInputSourceNode(cropNode, imageInputSlot) if (!sourceNode) return null return nodeOutputStore.getNodeImageUrls(sourceNode)?.[0] ?? null From 30b705da2f3eb3d27ada1675b3667cfad5988524 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Fri, 30 Oct 2026 23:12:11 +0900 Subject: [PATCH 3/6] fix: keep the Image Crop slot-0 fallback for inputs not typed IMAGE --- src/composables/useImageCrop.test.ts | 10 ++++++++++ src/composables/useImageCrop.ts | 14 +++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/composables/useImageCrop.test.ts b/src/composables/useImageCrop.test.ts index efe15156be4..e8d4ad69a30 100644 --- a/src/composables/useImageCrop.test.ts +++ b/src/composables/useImageCrop.test.ts @@ -448,6 +448,16 @@ describe('useImageCrop', () => { expect(vm.imageUrl).toBe('https://example.com/a.png') }) + it('shows the image connected after mount to a first input not typed IMAGE', async () => { + useLinkedCropNode([{ name: 'image', type: '*' }]) + const vm = await mountHarness() + + connectImageInput(0) + await flushTicks() + + expect(vm.imageUrl).toBe('https://example.com/a.png') + }) + it('shows the upstream image when the image input is not the first input, as after reopening a dynamic-input node', async () => { useLinkedCropNode([ { name: 'model', type: 'COMFY_DYNAMICCOMBO_V3' }, diff --git a/src/composables/useImageCrop.ts b/src/composables/useImageCrop.ts index aea8070d1de..3c84cc4c8a8 100644 --- a/src/composables/useImageCrop.ts +++ b/src/composables/useImageCrop.ts @@ -3,6 +3,7 @@ import type { Ref } from 'vue' import { computed, ref, watch } from 'vue' import { useLiveGraphNode } from '@/composables/useLiveGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/litegraph' import type { Bounds } from '@comfyorg/shared-frontend-utils/geometry' import { useNodeOutputStore } from '@/stores/nodeOutputStore' import type { NodeId } from '@comfyorg/graph-model/nodeId' @@ -67,6 +68,11 @@ interface UseImageCropOptions { onEditEnd?: () => void } +function imageInputSlot(node: LGraphNode): number { + const slot = node.inputs.findIndex((input) => input.type === 'IMAGE') + return slot === -1 ? 0 : slot +} + export function useImageCrop(nodeId: NodeId, options: UseImageCropOptions) { const { imageEl, containerEl, modelValue, onEditEnd } = options const nodeOutputStore = useNodeOutputStore() @@ -187,12 +193,10 @@ export function useImageCrop(nodeId: NodeId, options: UseImageCropOptions) { const cropNode = node.value if (!cropNode) return null - const imageInputSlot = cropNode.inputs.findIndex( - (input) => input.type === 'IMAGE' + const sourceNode = resolveInputSourceNode( + cropNode, + imageInputSlot(cropNode) ) - if (imageInputSlot === -1) return null - - const sourceNode = resolveInputSourceNode(cropNode, imageInputSlot) if (!sourceNode) return null return nodeOutputStore.getNodeImageUrls(sourceNode)?.[0] ?? null From 719ef958d47a140e831001854b91c2dd55f83398 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Fri, 30 Oct 2026 23:26:37 +0900 Subject: [PATCH 4/6] fix: match Image Crop sources that accept IMAGE, not only exact IMAGE --- src/composables/useImageCrop.test.ts | 12 ++++++++++++ src/composables/useImageCrop.ts | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/composables/useImageCrop.test.ts b/src/composables/useImageCrop.test.ts index e8d4ad69a30..29da215785c 100644 --- a/src/composables/useImageCrop.test.ts +++ b/src/composables/useImageCrop.test.ts @@ -472,6 +472,18 @@ describe('useImageCrop', () => { expect(vm.imageUrl).toBe('https://example.com/a.png') }) + it('shows the image from a union input before a later IMAGE input', async () => { + useLinkedCropNode([ + { name: 'image', type: 'IMAGE,MASK' }, + { name: 'reference', type: 'IMAGE' } + ]) + connectImageInput(0) + + const vm = await mountHarness() + + expect(vm.imageUrl).toBe('https://example.com/a.png') + }) + it('clears the preview when the image input is disconnected', async () => { useLinkedCropNode() connectImageInput() diff --git a/src/composables/useImageCrop.ts b/src/composables/useImageCrop.ts index 3c84cc4c8a8..4d8e9715387 100644 --- a/src/composables/useImageCrop.ts +++ b/src/composables/useImageCrop.ts @@ -4,6 +4,7 @@ import { computed, ref, watch } from 'vue' import { useLiveGraphNode } from '@/composables/useLiveGraphNode' import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' import type { Bounds } from '@comfyorg/shared-frontend-utils/geometry' import { useNodeOutputStore } from '@/stores/nodeOutputStore' import type { NodeId } from '@comfyorg/graph-model/nodeId' @@ -69,7 +70,9 @@ interface UseImageCropOptions { } function imageInputSlot(node: LGraphNode): number { - const slot = node.inputs.findIndex((input) => input.type === 'IMAGE') + const slot = node.inputs.findIndex((input) => + LiteGraph.isValidConnection('IMAGE', input.type) + ) return slot === -1 ? 0 : slot } From 2aecdaddfee0f3653d99f86e895f7146aa082897 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Fri, 30 Oct 2026 23:49:10 +0900 Subject: [PATCH 5/6] fix: keep Image Crop slot 0 on subgraph hosts --- src/composables/useImageCrop.test.ts | 29 ++++++++++++++++++++++++++++ src/composables/useImageCrop.ts | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/composables/useImageCrop.test.ts b/src/composables/useImageCrop.test.ts index 29da215785c..04c3413d45f 100644 --- a/src/composables/useImageCrop.test.ts +++ b/src/composables/useImageCrop.test.ts @@ -10,6 +10,10 @@ import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' import WidgetImageCrop from '@/components/imagecrop/WidgetImageCrop.vue' import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph' +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' import { useLinkStore } from '@/stores/linkStore' import { graphScopeOf } from '@comfyorg/graph-model/graphScopeId' import { toLinkId } from '@comfyorg/graph-model/linkId' @@ -484,6 +488,31 @@ describe('useImageCrop', () => { expect(vm.imageUrl).toBe('https://example.com/a.png') }) + it('shows an empty preview on a subgraph host with a later image input', async () => { + const subgraph = createTestSubgraph({ + inputs: [ + { name: 'prompt', type: 'STRING' }, + { name: 'image', type: 'IMAGE' } + ], + outputs: [{ name: 'out', type: 'IMAGE' }] + }) + const host = createTestSubgraphNode(subgraph, { id: 2 }) + mockResolveNode.mockReturnValue(host) + + const vm = await mountHarness() + + expect(vm.imageUrl).toBeNull() + }) + + it('shows the image connected to a custom input type through the slot-0 fallback', async () => { + useLinkedCropNode([{ name: 'image', type: 'CUSTOM_IMAGE' }]) + connectImageInput(0) + + const vm = await mountHarness() + + expect(vm.imageUrl).toBe('https://example.com/a.png') + }) + it('clears the preview when the image input is disconnected', async () => { useLinkedCropNode() connectImageInput() diff --git a/src/composables/useImageCrop.ts b/src/composables/useImageCrop.ts index 4d8e9715387..9e468aa9a90 100644 --- a/src/composables/useImageCrop.ts +++ b/src/composables/useImageCrop.ts @@ -70,6 +70,8 @@ interface UseImageCropOptions { } function imageInputSlot(node: LGraphNode): number { + if (node.isSubgraphNode()) return 0 + const slot = node.inputs.findIndex((input) => LiteGraph.isValidConnection('IMAGE', input.type) ) From 9922fa59753450f0b474d173a4662449a4d047a5 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Sat, 31 Oct 2026 00:08:52 +0900 Subject: [PATCH 6/6] test: link the custom-type fallback fixture with a matching type --- src/composables/useImageCrop.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/composables/useImageCrop.test.ts b/src/composables/useImageCrop.test.ts index 04c3413d45f..6fabaf75330 100644 --- a/src/composables/useImageCrop.test.ts +++ b/src/composables/useImageCrop.test.ts @@ -304,7 +304,7 @@ describe('useImageCrop', () => { mockResolveNode.mockReturnValue(cropNode) } - function connectImageInput(targetSlot = 0) { + function connectImageInput(targetSlot = 0, type = 'IMAGE') { useLinkStore().registerLink(GRAPH_SCOPE, { id: toLinkId(1), graphId: GRAPH_SCOPE.owningGraphId, @@ -312,7 +312,7 @@ describe('useImageCrop', () => { originSlot: 0, targetNodeId: CROP_NODE_ID, targetSlot, - type: 'IMAGE' + type }) } @@ -505,8 +505,13 @@ describe('useImageCrop', () => { }) it('shows the image connected to a custom input type through the slot-0 fallback', async () => { + sourceNode = createMockLGraphNode({ + id: 99, + isSubgraphNode: () => false, + outputs: [{ name: 'image', type: 'CUSTOM_IMAGE' }] + }) useLinkedCropNode([{ name: 'image', type: 'CUSTOM_IMAGE' }]) - connectImageInput(0) + connectImageInput(0, 'CUSTOM_IMAGE') const vm = await mountHarness()