Repository navigation
fix: add visual feedback for subgraph IO drag interactions #9838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c6f07f5
3958959
95c1643
724165c
a4f0ed9
a5dbe33
a15b3fd
1a71ad1
9dce47b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -489,6 +489,7 @@ export class LinkConnector { | |||||||||||||||||||||||||||||
| this.state.connectingTo = 'input' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| this._setLegacyLinks(false) | ||||||||||||||||||||||||||||||
| this.events.dispatch('connecting', { connectingTo: 'input' }) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| dragNewFromSubgraphOutput( | ||||||||||||||||||||||||||||||
|
|
@@ -513,6 +514,7 @@ export class LinkConnector { | |||||||||||||||||||||||||||||
| this.state.connectingTo = 'output' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| this._setLegacyLinks(true) | ||||||||||||||||||||||||||||||
| this.events.dispatch('connecting', { connectingTo: 'output' }) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
|
|
@@ -948,7 +950,10 @@ export class LinkConnector { | |||||||||||||||||||||||||||||
| (link: RenderLink) => !!link.disconnectOnDrop | ||||||||||||||||||||||||||||||
| ).forEach((link) => (link as { disconnect(): void }).disconnect()) | ||||||||||||||||||||||||||||||
| if (this.renderLinks.length === 0) return | ||||||||||||||||||||||||||||||
| // For external event only. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const intercepted = this.events.dispatch('before-drop-on-canvas', event) | ||||||||||||||||||||||||||||||
| if (intercepted === false) return | ||||||||||||||||||||||||||||||
|
Comment on lines
+954
to
+955
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🤖 get_repo_knowledge executed:
Length of output: 23769 🏁 Script executed: #!/bin/bash
set -eu
file="src/lib/litegraph/src/canvas/LinkConnector.ts"
printf '%s\n' '--- changed hunk context ---'
sed -n '900,985p' "$file"
printf '%s\n' '--- related symbols and call sites ---'
rg -n -C 4 "dropOnNothing|before-drop-on-canvas|disconnectOnDrop|renderLinks" src/lib/litegraph/src/canvas src/lib/litegraph/src | head -n 240
printf '%s\n' '--- event dispatch binding ---'
rg -n -C 5 "class .*Events|dispatch\\(|before-drop-on-canvas" src/lib/litegraph/src | head -n 240Repository: Comfy-Org/ComfyUI_frontend Length of output: 41782 🏁 Script executed: #!/bin/bash
set -eu
file="src/lib/litegraph/src/canvas/LinkConnector.ts"
printf '%s\n' '--- exact method and adjacent methods ---'
sed -n '850,985p' "$file"
printf '%s\n' '--- LinkConnector declarations and relevant types ---'
rg -n -C 5 "class LinkConnector|type RenderLink|interface RenderLink|disconnect\(\)|disconnectOnDrop|dropOnNothing" "$file" src/lib/litegraph/src | head -n 280Repository: Comfy-Org/ComfyUI_frontend Length of output: 25089 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- CustomEventTarget dispatch contract ---'
sed -n '1,180p' src/lib/litegraph/src/infrastructure/CustomEventTarget.ts
printf '%s\n' '--- all before-drop-on-canvas consumers ---'
rg -n -C 10 "before-drop-on-canvas" src | head -n 220
printf '%s\n' '--- disconnect implementations for affected link types ---'
rg -n -C 8 "class (MovingInputLink|MovingOutputLink|ToInputFromIoNodeLink)|disconnect\(\)" src/lib/litegraph/src/canvas/{MovingInputLink.ts,MovingOutputLink.ts,ToInputFromIoNodeLink.ts,RenderLink.ts} | head -n 300Repository: Comfy-Org/ComfyUI_frontend Length of output: 23244 🏁 Script executed: #!/bin/bash
set -eu
file="src/renderer/core/canvas/links/useSubgraphDragBridge.ts"
printf '%s\n' '--- bridge handler and drag lifecycle ---'
sed -n '1,175p' "$file"
printf '%s\n' '--- drop lifecycle around dropOnNothing ---'
sed -n '650,730p' src/lib/litegraph/src/canvas/LinkConnector.ts
printf '%s\n' '--- relevant drop-event tests with complete mock setup ---'
sed -n '1,100p' src/lib/litegraph/src/canvas/LinkConnectorDropEvents.test.tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 11048 Dispatch
Proposed fix dropOnNothing(event: CanvasPointerEvent): void {
+ if (this.renderLinks.length === 0) return
+
+ const intercepted = this.events.dispatch('before-drop-on-canvas', event)
+ if (intercepted === false) return
+
remove<RenderLinkUnion>(
this.renderLinks,
(link: RenderLink) => !!link.disconnectOnDrop
).forEach((link) => (link as { disconnect(): void }).disconnect())
if (this.renderLinks.length === 0) return
-
- const intercepted = this.events.dispatch('before-drop-on-canvas', event)
- if (intercepted === false) return📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const mayContinue = this.events.dispatch('dropped-on-canvas', event) | ||||||||||||||||||||||||||||||
| if (mayContinue === false) return | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
|
||
| import { LinkConnector } from '@/lib/litegraph/src/litegraph' | ||
| import { | ||
| createMockCanvasPointerEvent, | ||
| createMockLGraphNode, | ||
| createMockLinkNetwork, | ||
| createMockNodeOutputSlot | ||
| } from '@/utils/__tests__/litegraphTestUtils' | ||
|
|
||
| const mockSetConnectingLinks = vi.fn() | ||
|
|
||
| type RenderLinkItem = LinkConnector['renderLinks'][number] | ||
|
|
||
| function createMockRenderLink(): RenderLinkItem { | ||
| const partial: Partial<RenderLinkItem> = { | ||
| toType: 'input', | ||
| fromPos: [0, 0], | ||
| fromSlotIndex: 0, | ||
| fromDirection: 0, | ||
| network: createMockLinkNetwork(), | ||
| node: createMockLGraphNode(), | ||
| fromSlot: createMockNodeOutputSlot(), | ||
| dragDirection: 0, | ||
| canConnectToInput: vi.fn().mockReturnValue(false), | ||
| canConnectToOutput: vi.fn().mockReturnValue(false), | ||
| canConnectToReroute: vi.fn().mockReturnValue(false), | ||
| connectToInput: vi.fn(), | ||
| connectToOutput: vi.fn(), | ||
| connectToSubgraphInput: vi.fn(), | ||
| connectToRerouteOutput: vi.fn(), | ||
| connectToSubgraphOutput: vi.fn(), | ||
| connectToRerouteInput: vi.fn() | ||
| } | ||
| return partial as RenderLinkItem | ||
| } | ||
|
|
||
| describe('LinkConnector.dropOnNothing event dispatch', () => { | ||
| let connector: LinkConnector | ||
|
|
||
| beforeEach(() => { | ||
| connector = new LinkConnector(mockSetConnectingLinks) | ||
| }) | ||
|
|
||
| test('dispatches before-drop-on-canvas before dropped-on-canvas', () => { | ||
| connector.renderLinks.push(createMockRenderLink()) | ||
|
|
||
| const callOrder: string[] = [] | ||
| connector.events.addEventListener('before-drop-on-canvas', () => { | ||
| callOrder.push('before-drop-on-canvas') | ||
| }) | ||
| connector.events.addEventListener('dropped-on-canvas', () => { | ||
| callOrder.push('dropped-on-canvas') | ||
| }) | ||
|
|
||
| connector.dropOnNothing(createMockCanvasPointerEvent(100, 100)) | ||
|
|
||
| expect(callOrder).toEqual(['before-drop-on-canvas', 'dropped-on-canvas']) | ||
| }) | ||
|
|
||
| test('skips dropped-on-canvas when before-drop-on-canvas is intercepted', () => { | ||
| connector.renderLinks.push(createMockRenderLink()) | ||
|
|
||
| const droppedListener = vi.fn() | ||
| connector.events.addEventListener('before-drop-on-canvas', (e) => { | ||
| e.preventDefault() | ||
| }) | ||
| connector.events.addEventListener('dropped-on-canvas', droppedListener) | ||
|
|
||
| connector.dropOnNothing(createMockCanvasPointerEvent(100, 100)) | ||
|
|
||
| expect(droppedListener).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('does not dispatch events when renderLinks is empty', () => { | ||
| const beforeListener = vi.fn() | ||
| const droppedListener = vi.fn() | ||
| connector.events.addEventListener('before-drop-on-canvas', beforeListener) | ||
| connector.events.addEventListener('dropped-on-canvas', droppedListener) | ||
|
|
||
| connector.dropOnNothing(createMockCanvasPointerEvent(100, 100)) | ||
|
|
||
| expect(beforeListener).not.toHaveBeenCalled() | ||
| expect(droppedListener).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { describe, expect, vi } from 'vitest' | ||
|
|
||
| import { LGraphNode } from '@/lib/litegraph/src/litegraph' | ||
| import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' | ||
|
|
||
| import { subgraphTest } from './__fixtures__/subgraphFixtures' | ||
|
|
||
| describe('SubgraphInput.connect triggers node:slot-links:changed', () => { | ||
| subgraphTest( | ||
| 'fires connected event when connecting to a widget input', | ||
| ({ simpleSubgraph }) => { | ||
| const subgraph = simpleSubgraph | ||
| const triggerSpy = vi.spyOn(subgraph, 'trigger') | ||
|
|
||
| const node = new LGraphNode('Target') | ||
| node.addInput('prompt', 'STRING') | ||
| node.inputs[0].widget = { name: 'prompt' } | ||
| subgraph.add(node) | ||
|
|
||
| subgraph.inputNode.slots[0].connect(node.inputs[0], node) | ||
|
|
||
| expect(triggerSpy).toHaveBeenCalledWith('node:slot-links:changed', { | ||
| nodeId: node.id, | ||
| slotType: NodeSlotType.INPUT, | ||
| slotIndex: 0, | ||
| connected: true, | ||
| linkId: expect.any(Number) | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
| subgraphTest( | ||
| 'does not fire event when connecting to a non-widget input', | ||
| ({ simpleSubgraph }) => { | ||
| const subgraph = simpleSubgraph | ||
| const triggerSpy = vi.spyOn(subgraph, 'trigger') | ||
|
|
||
| const node = new LGraphNode('Target') | ||
| node.addInput('in', 'number') | ||
| subgraph.add(node) | ||
|
|
||
| subgraph.inputNode.slots[0].connect(node.inputs[0], node) | ||
|
|
||
| expect(triggerSpy.mock.calls.map((c) => c[0])).not.toContain( | ||
| 'node:slot-links:changed' | ||
| ) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| describe('SubgraphInputNode._disconnectNodeInput triggers node:slot-links:changed', () => { | ||
| subgraphTest( | ||
| 'fires disconnected event when disconnecting a widget input', | ||
| ({ simpleSubgraph }) => { | ||
| const subgraph = simpleSubgraph | ||
|
|
||
| const node = new LGraphNode('Target') | ||
| node.addInput('prompt', 'STRING') | ||
| node.inputs[0].widget = { name: 'prompt' } | ||
| subgraph.add(node) | ||
|
|
||
| const link = subgraph.inputNode.slots[0].connect(node.inputs[0], node) | ||
| expect(link).toBeDefined() | ||
|
|
||
| const triggerSpy = vi.spyOn(subgraph, 'trigger') | ||
|
|
||
| subgraph.inputNode._disconnectNodeInput(node, node.inputs[0], link!) | ||
|
|
||
| expect(triggerSpy).toHaveBeenCalledWith('node:slot-links:changed', { | ||
| nodeId: node.id, | ||
| slotType: NodeSlotType.INPUT, | ||
| slotIndex: 0, | ||
| connected: false, | ||
| linkId: link!.id | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
| subgraphTest( | ||
| 'does not fire event when disconnecting a non-widget input', | ||
| ({ simpleSubgraph }) => { | ||
| const subgraph = simpleSubgraph | ||
|
|
||
| const node = new LGraphNode('Target') | ||
| node.addInput('in', 'number') | ||
| subgraph.add(node) | ||
|
|
||
| const link = subgraph.inputNode.slots[0].connect(node.inputs[0], node) | ||
| expect(link).toBeDefined() | ||
|
|
||
| const triggerSpy = vi.spyOn(subgraph, 'trigger') | ||
|
|
||
| subgraph.inputNode._disconnectNodeInput(node, node.inputs[0], link!) | ||
|
|
||
| expect(triggerSpy.mock.calls.map((c) => c[0])).not.toContain( | ||
| 'node:slot-links:changed' | ||
| ) | ||
| } | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mounting this bridge immediately reads
lgCanvas.getCanvasWindow(), but the existing GraphCanvas test fixture does not provide that method.pnpm test:unit src/components/graph/GraphCanvas.test.tsfails 12/14 tests here withTypeError: lgCanvas.getCanvasWindow is not a function. Update the fixture or isolate the bridge dependency so the existing component contract remains testable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reproduced, with one correction to the diagnosis, then fixed properly.
On the head you reviewed the mount did throw, but on
linkConnector.events(Cannot read properties of undefined (reading 'events')), not ongetCanvasWindow.getCanvasWindow()is only reached fromstartPointerTracking, which runs on aconnectingevent, never at mount. Same 12/14 outcome, different line. That throw was fixed in a15b3fd, so on today's headpnpm test:unit src/components/graph/GraphCanvas.test.tsis 12 passed / 2 expected fail (14), exit 0. The twoit.failsare in the execution-progress describe and predate this PR.On your two remedies: I took the fixture, not a restructure.
linkConnectoris non-optional onLGraphCanvas, and GraphCanvas already mounts a dozen-plus composables off the live canvas, so the fixture was under-specifying the type rather than the component acquiring a new coupling. Deferring or injecting the connector would add indirection without removing the dependency.But the "remains testable" half of your comment stood on its own, and the fixture alone does not satisfy it: a stub that only stops a throw means nothing notices if the bridge quietly stops wiring itself up. So 1a71ad1 adds
src/renderer/core/canvas/links/useSubgraphDragBridge.test.ts, four tests against anLGraphCanvasdouble, covering drag mirroring, per-slot compatibility, reset, and scope-dispose teardown.Mutation-checked so it is not stubbed into silence:
getCanvasWindowfrom the canvas doubleTypeError: lgCanvas.getCanvasWindow is not a functionconnectinglistenerresetlistenersetCompatibleForKeyfrom the connecting loopendDrag()from cleanupThe first row is the point: the method you named is genuinely reached, and the fixture value it returns is used rather than ignored.
Separately, 9dce47b clears the red lint-and-format.
comfy/no-redundant-vitest-cleanupwas firing on avi.clearAllMocks()this PR added inLinkConnectorDropEvents.test.ts.Gates on 9dce47b:
pnpm typecheckexit 0 (verified live with an injected error),pnpm lint:no-cacheexit 0 (187 pre-existingapiSchemawarnings, 0 errors; oxlint liveness confirmed by re-inserting the violation),format:checkandknipclean, and the five test files this PR touches pass 25/25 plus the 2 pre-existing expected-fails. The redstorybook-buildis a rolldown chunk-naming error that I cannot reproduce;pnpm build-storybookon this head exits 0 locally, so it looks like infra and should clear on rerun.One thing I did not do, and want your call on. The branch conflicts with
mainin exactly one file,useSlotLinkInteraction.ts, so the mechanical merge is small. The real question is whether the feature still belongs: ADR 0009 landed in #12197 back in May, and @artokun said above he was ready to update once it did. Happy to rebase and rework the bridge onto the post-ADR-0009 slot ownership model, or to close this in favour of a fresh PR, but that is a scope decision rather than something I should just do on a six-month-old branch. Reassigning to you.