Repository navigation
Support fast disco on subgraph IO - #12619
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughAdds optional disconnect-on-drop fields to render links, initializes disconnect origin in link construction, updates canvas rendering and drop logic to honor the new fields, renames a test fixture helper, and adds a Playwright test for fast vs normal disconnection. ChangesFast disconnection support
Sequence DiagramsequenceDiagram
participant LGraphCanvas
participant RenderLink
participant LinkConnector
LGraphCanvas->>RenderLink: iterate renderLinks, read `disconnectOrigin`
LGraphCanvas->>RenderLink: draw disconnect outline when pointer within radius
LGraphCanvas->>RenderLink: set `disconnectOnDrop` based on proximity
LinkConnector->>RenderLink: remove entries where `disconnectOnDrop` true and call `disconnect()`
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 4❌ Failed checks (3 warnings, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🎭 Playwright: ✅ 1659 passed, 0 failed · 1 flaky📊 Browser Reports
|
🎨 Storybook: ✅ Built — View Storybook |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
src/lib/litegraph/src/canvas/LinkConnector.ts (1)
876-879: 💤 Low valueConsider type guard for
disconnect()capability.The code now uses a generic
disconnectOnDropcheck and casts to{ disconnect(): void }. This assumes anyRenderLinkwithdisconnectOnDrop=truealso has adisconnect()method—an implicit contract not enforced by types. Per learnings from PR 7459, prefer user-defined type guards over casts in LiteGraph code for better type safety and reusability.♻️ Optional type guard approach
// Define a type guard for disconnectable links function isDisconnectableLink( link: RenderLink ): link is RenderLink & { disconnect(): boolean } { return !!link.disconnectOnDrop && 'disconnect' in link } // Usage: remove(this.renderLinks, isDisconnectableLink).forEach(link => link.disconnect())This approach provides compile-time safety and avoids the cast.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/litegraph/src/canvas/LinkConnector.ts` around lines 876 - 879, Replace the unsafe cast by adding a user-defined type guard that narrows RenderLink to a disconnect-capable type and use it with remove(this.renderLinks, ...). Specifically, implement an isDisconnectableLink(link: RenderLink): link is RenderLink & { disconnect(): void } that checks link.disconnectOnDrop and that 'disconnect' exists on the object, then call remove(this.renderLinks, isDisconnectableLink).forEach(link => link.disconnect()); update usages referencing RenderLink, renderLinks, disconnectOnDrop and disconnect() accordingly.src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts (1)
173-190: 💤 Low valueCode duplication with
MovingInputLink.drawConnectionCircle.This implementation is nearly identical to
MovingInputLink.drawConnectionCircle(per context snippet lines 141-158). The only difference is the additional!this.disconnectOriginguard. Consider extracting the shared circle-drawing logic into a utility function to improve maintainability.♻️ Example utility extraction
// In a shared utility file: function drawDisconnectCircle( ctx: CanvasRenderingContext2D, origin: Point, to: Readonly<Point>, radius = 35 ): boolean { const [originX, originY] = origin const distSquared = (originX - to[0]) ** 2 + (originY - to[1]) ** 2 ctx.save() ctx.strokeStyle = LiteGraph.WIDGET_OUTLINE_COLOR ctx.lineWidth = 2 ctx.beginPath() ctx.moveTo(originX + radius, originY) ctx.arc(originX, originY, radius, 0, Math.PI * 2) ctx.stroke() ctx.restore() return distSquared < radius ** 2 } // Usage in drawConnectionCircle: drawConnectionCircle(ctx: CanvasRenderingContext2D, to: Readonly<Point>) { if (!this.disconnectOnDrop || !this.disconnectOrigin) return this.disconnectOnDrop = drawDisconnectCircle(ctx, this.disconnectOrigin, to) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts` around lines 173 - 190, The drawConnectionCircle implementation in ToInputFromIoNodeLink duplicates logic from MovingInputLink.drawConnectionCircle; extract the shared circle-drawing and distance-check into a single utility (e.g., drawDisconnectCircle) that accepts (ctx, origin: Point, to: Readonly<Point>, radius?) and returns the boolean hit-test, then replace both ToInputFromIoNodeLink.drawConnectionCircle and MovingInputLink.drawConnectionCircle to early-return on !this.disconnectOnDrop or !this.disconnectOrigin and call the new utility to set this.disconnectOnDrop; reference the existing methods ToInputFromIoNodeLink.drawConnectionCircle and MovingInputLink.drawConnectionCircle when applying the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@browser_tests/tests/vueNodes/interactions/links/linkInteraction.spec.ts`:
- Around line 1243-1249: The fast branch currently skips any positive
verification because it never waits for the context menu and the final
toBeHidden check is a no-op; after the fast drag (when isFast is true) add an
explicit assertion that the link was removed (e.g. assert the link element/state
is absent or the link count decreased) using the same page helpers you use
elsewhere in this spec rather than relying on the context menu; locate the fast
branch around isFast, comfyPage.contextMenu.litegraphContextMenu and
comfyMouse.click(100, 100) and insert a check (via the test helper that queries
links on comfyPage or the graph/link selector used in this file) to confirm the
target link no longer exists.
- Around line 1261-1270: The test calls comfyPage.vueNodes.enterSubgraph() but
doesn’t adjust the viewport, causing comfyMouse.resizeByDragging() to throw and
the disconnection assertions to be flaky; after calling
comfyPage.vueNodes.enterSubgraph() add fitToViewInstant(comfyPage) to ensure
nodes/slots are in view, then after
performDisconnect(ksampler.getSlot('negative'), true) and
performDisconnect(ksampler.getSlot('latent_image'), false) add assertions using
getInputLinkDetails(ksampler.getSlot(...)) to verify the slot link state changed
as expected (fast vs normal disconnect); keep references to enterSubgraph,
fitToViewInstant, performDisconnect, and getInputLinkDetails when making the
changes.
- Around line 1240-1259: The test currently only checks the context menu
visibility in performDisconnect and must also assert link counts: before calling
performDisconnect capture countBefore via ksampler.getNode() or the node
reference then compute index = node.inputs.findIndex(input => input.name ===
slotName) and access ksampler.getInput(index).getLinkCount(); for the fast-path
call (isFast true) assert that getLinkCount() becomes 0 after performDisconnect,
and for the normal/cancelled path (isFast false) assert the link count remains
equal to countBefore; update performDisconnect usage for 'model' and 'positive'
slots to compute the correct input indices as shown and add these assertions
around the calls using NodeSlotReference.getLinkCount() /
NodeReference.getInput(i).
In `@src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts`:
- Around line 50-54: Set disconnectOnDrop only when there is an existing link:
instead of unconditionally assigning this.disconnectOnDrop = true in the
ToInputFromIoNodeLink constructor, check if existingLink is truthy and then set
this.disconnectOnDrop = true and compute this.disconnectOrigin via
network.getNodeById(existingLink.target_id).getInputPos(existingLink.target_slot);
otherwise set this.disconnectOnDrop = false (or leave undefined/false). This
ensures disconnectOnDrop and disconnectOrigin are consistently initialized based
on existingLink so dropOnNothing and disconnect() logic only run for real
existing links.
---
Nitpick comments:
In `@src/lib/litegraph/src/canvas/LinkConnector.ts`:
- Around line 876-879: Replace the unsafe cast by adding a user-defined type
guard that narrows RenderLink to a disconnect-capable type and use it with
remove(this.renderLinks, ...). Specifically, implement an
isDisconnectableLink(link: RenderLink): link is RenderLink & { disconnect():
void } that checks link.disconnectOnDrop and that 'disconnect' exists on the
object, then call remove(this.renderLinks, isDisconnectableLink).forEach(link =>
link.disconnect()); update usages referencing RenderLink, renderLinks,
disconnectOnDrop and disconnect() accordingly.
In `@src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts`:
- Around line 173-190: The drawConnectionCircle implementation in
ToInputFromIoNodeLink duplicates logic from
MovingInputLink.drawConnectionCircle; extract the shared circle-drawing and
distance-check into a single utility (e.g., drawDisconnectCircle) that accepts
(ctx, origin: Point, to: Readonly<Point>, radius?) and returns the boolean
hit-test, then replace both ToInputFromIoNodeLink.drawConnectionCircle and
MovingInputLink.drawConnectionCircle to early-return on !this.disconnectOnDrop
or !this.disconnectOrigin and call the new utility to set this.disconnectOnDrop;
reference the existing methods ToInputFromIoNodeLink.drawConnectionCircle and
MovingInputLink.drawConnectionCircle when applying the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8819418e-30ae-4f98-9b73-1d786a745447
📒 Files selected for processing (5)
browser_tests/tests/vueNodes/interactions/links/linkInteraction.spec.tssrc/lib/litegraph/src/LGraphCanvas.tssrc/lib/litegraph/src/canvas/LinkConnector.tssrc/lib/litegraph/src/canvas/RenderLink.tssrc/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #12619 +/- ##
===========================================
- Coverage 75.17% 60.81% -14.36%
===========================================
Files 1557 1446 -111
Lines 91065 74490 -16575
Branches 24044 20996 -3048
===========================================
- Hits 68455 45304 -23151
- Misses 21883 28826 +6943
+ Partials 727 360 -367
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| { tag: '@vue-nodes' }, | ||
| async ({ comfyMouse, comfyPage }) => { | ||
| async function performDisconnect(slot: Locator, isFast: boolean) { | ||
| await comfyMouse.resizeByDragging(slot, { x: isFast ? -25 : -80 }) |
There was a problem hiding this comment.
resizeByDragging probably needs a rename... dragElementBy?
There was a problem hiding this comment.
I think worth doing as this reads very weirdly in this context
| drawConnectionCircle(ctx: CanvasRenderingContext2D, to: Readonly<Point>) { | ||
| if (!this.disconnectOnDrop || !this.disconnectOrigin) return | ||
|
|
||
| const [originX, originY] = this.disconnectOrigin |
There was a problem hiding this comment.
Can you extract a shared function from MovingInputLink drawConnectionCircle and use that in both places
There was a problem hiding this comment.
I've opted to inline the function instead. It solves the need of finding a place to put the code and lets me move the _getHighlightPosition call inside so that it only runs when required.
8e2af47 to
0f4bc5d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts (1)
49-53:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winConditionally initialize
disconnectOnDropbased onexistingLinkpresence.Setting
disconnectOnDrop = trueunconditionally is semantically incorrect when creating a new link (noexistingLink). When no existing link is present, there is nothing to disconnect, so the flag should befalse. Thedisconnect()method guards against this at line 158, so it won't crash, but it causes unnecessary overhead in drop handling and is confusing.🔧 Proposed fix
- this.disconnectOnDrop = true - - if (!existingLink) return + this.disconnectOnDrop = !!existingLink + if (!existingLink) return + const toNode = network.getNodeById(existingLink.target_id) this.disconnectOrigin = toNode?.getInputPos(existingLink.target_slot)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts` around lines 49 - 53, The code currently sets disconnectOnDrop = true unconditionally even when existingLink is null; change it to only enable disconnection when an existingLink exists (e.g., set disconnectOnDrop = Boolean(existingLink) or move the assignment inside the if (existingLink) block), and keep the existing logic that sets disconnectOrigin via network.getNodeById(existingLink.target_id)?.getInputPos(existingLink.target_slot) so disconnect() can use it safely; this removes unnecessary drop-handling overhead when creating a new link.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/litegraph/src/LGraphCanvas.ts`:
- Around line 6158-6176: The loop early-returns when link.disconnectOnDrop is
false which prevents recomputing it later; change the guard in the render loop
over linkConnector.renderLinks so it only skips when disconnectOrigin is missing
(e.g., replace "if (!link.disconnectOnDrop || !link.disconnectOrigin) return"
with "if (!link.disconnectOrigin) return"), then keep the existing distance
check using this._getHighlightPosition() to set link.disconnectOnDrop =
distSquared < radius ** 2 so the flag can flip true again when the cursor
re-enters.
---
Duplicate comments:
In `@src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts`:
- Around line 49-53: The code currently sets disconnectOnDrop = true
unconditionally even when existingLink is null; change it to only enable
disconnection when an existingLink exists (e.g., set disconnectOnDrop =
Boolean(existingLink) or move the assignment inside the if (existingLink)
block), and keep the existing logic that sets disconnectOrigin via
network.getNodeById(existingLink.target_id)?.getInputPos(existingLink.target_slot)
so disconnect() can use it safely; this removes unnecessary drop-handling
overhead when creating a new link.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 27830792-456d-421d-b81f-270fe40b6d79
📒 Files selected for processing (9)
browser_tests/fixtures/ComfyMouse.tsbrowser_tests/tests/vueNodes/interactions/links/linkInteraction.spec.tsbrowser_tests/tests/vueNodes/interactions/node/imagePreview.spec.tsbrowser_tests/tests/vueNodes/widgets/legacy.spec.tssrc/lib/litegraph/src/LGraphCanvas.tssrc/lib/litegraph/src/canvas/LinkConnector.tssrc/lib/litegraph/src/canvas/MovingInputLink.tssrc/lib/litegraph/src/canvas/RenderLink.tssrc/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/lib/litegraph/src/canvas/RenderLink.ts
- src/lib/litegraph/src/canvas/LinkConnector.ts
- browser_tests/tests/vueNodes/interactions/links/linkInteraction.spec.ts
Because subgraph links don't follow the normal link logic, the fast disconnection circle would not function when dragging input links that originate from a subgraph IO node. There's some sad duplication of state, but I think the flow is marginally cleaner now by not requiring `instanceof` checks. The test added by this PR also verifies behavior for the node-to-node case.
Because subgraph links don't follow the normal link logic, the fast disconnection circle would not function when dragging input links that originate from a subgraph IO node. There's some sad duplication of state, but I think the flow is marginally cleaner now by not requiring `instanceof` checks. The test added by this PR also verifies behavior for the node-to-node case.
Because subgraph links don't follow the normal link logic, the fast disconnection circle would not function when dragging input links that originate from a subgraph IO node. There's some sad duplication of state, but I think the flow is marginally cleaner now by not requiring
instanceofchecks.The test added by this PR also verifies behavior for the node-to-node case.