Skip to content

fix: add visual feedback for subgraph IO drag interactions - #9281

Closed
artokun wants to merge 4 commits into
Comfy-Org:mainfrom
artokun:fix/subgraph-io-drag-feedback
Closed

artokun wants to merge 4 commits into
Comfy-Org:mainfrom
artokun:fix/subgraph-io-drag-feedback

Conversation

@artokun

@artokun artokun commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Subgraph IO nodes (canvas-drawn) have no visual feedback when dragging links to/from Vue-rendered nodes inside a subgraph — no slot dimming, no proximity snap, no dot highlight, and connections silently fail when releasing on a snapped candidate.

The core problem is that these two rendering layers don't share pointer state. Vue-initiated drags never call SubgraphIONodeBase.onPointerMove(), and canvas-initiated drags never touch the Vue slotLinkDragUIState. I couldn't find an existing mechanism to bridge this gap — if there's a built-in way to propagate drag context between canvas and Vue that I'm missing, I'd genuinely love to know about it. The approach here is a bridge composable (useSubgraphDragBridge) that translates LinkConnector events into Vue drag state mutations, and a symmetric addition in processPointerMoveFrame for the reverse direction.

Changes

  • What: Added useSubgraphDragBridge composable that listens to LinkConnector events (connecting, before-drop-on-canvas, reset) and drives the Vue slotLinkDragUIState — enabling slot dimming, proximity snap, snap-target highlighting, and drop-to-connect for canvas-to-Vue drags. For Vue-to-canvas drags, extended processPointerMoveFrame to call SubgraphIONodeBase.onPointerMove() with a synthetic event, driving the canvas-side slot dot highlights and link snapping. Also fires node:slot-links:changed from SubgraphInput.connect() and SubgraphInputNode._disconnectNodeInput() so widget input dots update immediately on cross-layer connections.

Fixes #9010

Review Focus

  • The bridge composable is the main addition — it mirrors the pointermove tracking pattern from useSlotLinkInteraction but operates on document-level events since canvas pointer capture suppresses DOM hover states on Vue elements. I'd appreciate a close look at the lifecycle cleanup and the isBridgeDrag ownership guard.
  • SlotConnectionDot.vue adds group-[.lg-slot--snap-target]/slot: Tailwind variants alongside the existing group-hover/slot: ones. This is needed because canvas pointer capture suppresses CSS :hover on Vue elements during canvas-initiated drags — the bridge adds/removes the lg-slot--snap-target class programmatically instead.
  • The before-drop-on-canvas event on LinkConnector fires before dropped-on-canvas and is cancelable — the bridge intercepts it to connect to the snapped Vue candidate before the canvas search dialog would appear.

Demo

Screen.Recording.2026-02-26.at.8.58.29.PM.mov

┆Issue is synchronized with this Notion page by Unito

@artokun
artokun requested review from a team and benceruleanlu as code owners February 27, 2026 05:17
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 27, 2026
@coderabbitai

coderabbitai Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a subgraph drag bridge linking canvas-initiated subgraph IO drags to the Vue slot-drag UI state, introduces events to intercept canvas drops, emits slot-link change events on subgraph IO connect/disconnect, and updates slot hover/snap handling and visuals for live feedback.

Changes

Cohort / File(s) Summary
Graph Canvas Integration
src/components/graph/GraphCanvas.vue
Import and invoke useSubgraphDragBridge() in setup to enable the bridge.
Bridge Implementation
src/renderer/core/canvas/links/useSubgraphDragBridge.ts
New exported module implementing the bridge: subscribes to LinkConnector events, adapts render links, RAF-batched pointer tracking, computes compatibility/candidates, updates snap state, and connects candidates on drop.
Link Connector Core & Events
src/lib/litegraph/src/canvas/LinkConnector.ts, src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts
Emit connecting with `{ connectingTo: 'input'
Subgraph Slot Notifications
src/lib/litegraph/src/subgraph/SubgraphInput.ts, src/lib/litegraph/src/subgraph/SubgraphInputNode.ts
Emit node:slot-links:changed on connect/disconnect for widget-backed inputs, including nodeId, slotType: INPUT, slotIndex, connected boolean, and linkId.
Slot Interaction & UI
src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts, src/renderer/extensions/vueNodes/components/SlotConnectionDot.vue
Detect subgraph IO nodes during interactions, compute subgraph IO snap positions, trigger redraws on subgraph hover/snap changes; add Tailwind variants to highlight snap targets.
Tests
src/lib/litegraph/src/canvas/LinkConnectorDropEvents.test.ts, src/lib/litegraph/src/subgraph/SubgraphIOSlotLinks.test.ts
New tests covering before-drop-on-canvas interception/dropped-on-canvas ordering and subgraph IO slot link connect/disconnect events.
Minor
src/renderer/core/canvas/links/linkConnectorAdapter.ts
Removed an obsolete comment in dropOnCanvas (no functional change).

Sequence Diagram

sequenceDiagram
    participant Canvas as Canvas
    participant LinkConnector as LinkConnector
    participant Bridge as SubgraphDragBridge
    participant UIState as Slot UI State
    participant Slot as Slot Component

    Canvas->>LinkConnector: start drag from Subgraph IO
    LinkConnector->>Bridge: emit "connecting" { connectingTo }
    Bridge->>Bridge: create adapter & compute compatibility
    Bridge->>UIState: begin drag (set candidate & snap position)

    Canvas->>LinkConnector: pointer move events
    LinkConnector->>Bridge: forward pointer updates
    Bridge->>Bridge: RAF pointer tracking -> resolve target
    Bridge->>UIState: update candidate & snap position
    UIState->>Slot: apply `lg-slot--snap-target` class (visual highlight)

    Canvas->>LinkConnector: drop event
    LinkConnector->>Bridge: emit "before-drop-on-canvas"
    Bridge->>Bridge: connectToCandidate() (if compatible)
    Bridge->>Canvas: perform connection / end drag
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰
I hop across the canvas wide,
A tiny bridge from side to side,
A dot that snaps, a light that gleams,
Connections born from gentle dreams,
Now subgraphs meet where once was hide.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding visual feedback for subgraph IO drag interactions, which aligns with the core objective of the PR.
Description check ✅ Passed The description provides a comprehensive summary, detailed changes, review focus areas, and a demo link, covering all required template sections with substantial detail.
Linked Issues check ✅ Passed The PR successfully addresses issue #9010 by adding visual feedback for subgraph IO drag interactions through the useSubgraphDragBridge composable, pointer tracking, snap-target highlighting, and drop-to-connect functionality.
Out of Scope Changes check ✅ Passed All changes are directly scoped to enabling visual feedback for subgraph IO drags: bridge composable, event emission, pointer tracking, Tailwind styling updates, and supporting tests. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

🎨 Storybook: loading Building...

* (canvas-drawn), the Vue slot components need to know about it so they
* can dim incompatible slots, snap links, and highlight compatible targets.
*/
export function useSubgraphDragBridge() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This composable exists because SubgraphInput/Output nodes are canvas-drawn while regular nodes are Vue-rendered — during a canvas-initiated drag, pointer capture is on the <canvas> element, so Vue slot components never receive hover events. The bridge listens to LinkConnector events and translates them into slotLinkDragUIState mutations so Vue components can react (dimming, snap highlights). The reverse direction (Vue-to-canvas) is handled in useSlotLinkInteraction.ts instead, since the pointermove handler already lives there.

@github-actions

github-actions Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright: ⏳ Running...

: 'size-3 cursor-crosshair group-hover/slot:[--node-component-slot-dot-outline-opacity-mult:5] group-hover/slot:scale-125'
: 'size-3 cursor-crosshair group-hover/slot:[--node-component-slot-dot-outline-opacity-mult:5] group-hover/slot:scale-125 group-[.lg-slot--snap-target]/slot:[--node-component-slot-dot-outline-opacity-mult:5] group-[.lg-slot--snap-target]/slot:scale-125'
)
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The group-hover/slot: variants work for Vue-to-Vue drags because useSlotLinkInteraction doesn't call setPointerCapture — CSS :hover fires naturally. But canvas-initiated drags call CanvasPointer.down() → setPointerCapture() on the <canvas>, which suppresses :hover on all other elements. The bridge toggles lg-slot--snap-target on the group/slot parent element to replicate the same visual effect programmatically.

@@ -878,7 +880,10 @@

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, releasing a canvas-initiated drag over a snapped Vue slot would miss the connection — dropOnNothing() does geometric hit-testing in canvas space which can't find Vue DOM nodes. The bridge listens for before-drop-on-canvas, connects to the snapped candidate from dragState, and calls preventDefault() to stop dropped-on-canvas (which would open the search dialog).

connected: true,
linkId: link.id
})
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trigger was missing — SubgraphInput.connect() establishes the link but never notified the Vue layer. Without it, widget input dots (the connected state indicator) don't appear until some other Vue action forces a re-render. Mirrors the pattern in LGraphNode.connect().

if (wasPointerOver !== node.isPointerOver || node.isPointerOver) {
subgraphIOHoverChanged = true
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles the reverse direction — Vue-to-canvas. During Vue-initiated drags, LGraphCanvas.processMouseMove() is never called, so SubgraphIONodeBase.onPointerMove() never fires. The synthetic event only needs canvasX/canvasY (already computed above). onPointerMove() handles both enter/leave transitions internally, so cleanup is automatic when the pointer moves away.

Bridge canvas-initiated subgraph IO drags to Vue slot drag state and
vice versa, restoring slot dimming, proximity snap, dot highlights,
and drop-to-connect across the canvas/Vue rendering boundary.

Fixes Comfy-Org#9010
@artokun
artokun force-pushed the fix/subgraph-io-drag-feedback branch from 75a3585 to 376a1e9 Compare February 27, 2026 05:22
@artokun

artokun commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Tagging @christian-byrne for current Subgraph Node open PRs. Don't wanna step on anything you're working on!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts (1)

545-547: ⚠️ Potential issue | 🟡 Minor

Duplicate raf.flush() calls.

There are two consecutive raf.flush() calls on lines 545 and 547. This appears to be a copy-paste error.

Proposed fix
     raf.flush()

-    raf.flush()
-
     if (!state.source) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts`
around lines 545 - 547, The code contains duplicate consecutive raf.flush()
calls in the useSlotLinkInteraction composable—remove the redundant second call
so only a single raf.flush() remains; locate the raf.flush() invocations inside
the useSlotLinkInteraction function and delete the duplicate line to avoid
unnecessary double flushing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts`:
- Around line 545-547: The code contains duplicate consecutive raf.flush() calls
in the useSlotLinkInteraction composable—remove the redundant second call so
only a single raf.flush() remains; locate the raf.flush() invocations inside the
useSlotLinkInteraction function and delete the duplicate line to avoid
unnecessary double flushing.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75a3585 and e25bf74.

📒 Files selected for processing (9)
  • src/components/graph/GraphCanvas.vue
  • src/lib/litegraph/src/canvas/LinkConnector.ts
  • src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts
  • src/lib/litegraph/src/subgraph/SubgraphInput.ts
  • src/lib/litegraph/src/subgraph/SubgraphInputNode.ts
  • src/renderer/core/canvas/links/linkConnectorAdapter.ts
  • src/renderer/core/canvas/links/useSubgraphDragBridge.ts
  • src/renderer/extensions/vueNodes/components/SlotConnectionDot.vue
  • src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts
💤 Files with no reviewable changes (1)
  • src/renderer/core/canvas/links/linkConnectorAdapter.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts
  • src/lib/litegraph/src/subgraph/SubgraphInput.ts
  • src/lib/litegraph/src/canvas/LinkConnector.ts
  • src/components/graph/GraphCanvas.vue

- SubgraphInput.connect() fires node:slot-links:changed for widget inputs
- SubgraphInputNode._disconnectNodeInput() fires on disconnect
- LinkConnector.dropOnNothing() dispatches before-drop-on-canvas before
  dropped-on-canvas, and skips downstream when intercepted
- Remove duplicate raf.flush() in finishInteraction
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts (1)

404-406: Avoid unconditional canvas dirtying during stable hover.

At Line 404, || node.isPointerOver makes subgraphIOHoverChanged true for every pointer move while hovering. That causes Line 439 to call setDirty(true, true) even when nothing changed, which can hurt drag smoothness.

♻️ Proposed fix
-        if (wasPointerOver !== node.isPointerOver || node.isPointerOver) {
+        if (wasPointerOver !== node.isPointerOver) {
           subgraphIOHoverChanged = true
         }

Also applies to: 437-439

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts`
around lines 404 - 406, The hover-change flag is being set unconditionally while
pointer is over a node due to the `|| node.isPointerOver` logic; update the
condition so `subgraphIOHoverChanged` is only set when the hover state actually
toggles (i.e., when `wasPointerOver !== node.isPointerOver`) and remove the `||
node.isPointerOver` clause; apply the same fix to the duplicate logic around the
other block that sets `subgraphIOHoverChanged` (the lines near where
`setDirty(true, true)` is called) so `setDirty` is only invoked when the hover
state truly changed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/litegraph/src/subgraph/SubgraphIOSlotLinks.test.ts`:
- Around line 44-47: The test's negative assertion is too weak—replace
expect(triggerSpy).not.toHaveBeenCalledWith('node:slot-links:changed',
expect.anything()) with an assertion that no call used that event name (e.g.
collect triggerSpy.mock.calls.map(c => c[0]) and assert
.not.toContain('node:slot-links:changed')) so an emitted event with undefined
payload won't slip through; apply the identical change to the "disconnect
non-widget" test (the other assertion at lines 96-99) in
SubgraphIOSlotLinks.test.ts.

---

Nitpick comments:
In `@src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts`:
- Around line 404-406: The hover-change flag is being set unconditionally while
pointer is over a node due to the `|| node.isPointerOver` logic; update the
condition so `subgraphIOHoverChanged` is only set when the hover state actually
toggles (i.e., when `wasPointerOver !== node.isPointerOver`) and remove the `||
node.isPointerOver` clause; apply the same fix to the duplicate logic around the
other block that sets `subgraphIOHoverChanged` (the lines near where
`setDirty(true, true)` is called) so `setDirty` is only invoked when the hover
state truly changed.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e25bf74 and 772cfe8.

📒 Files selected for processing (3)
  • src/lib/litegraph/src/canvas/LinkConnectorDropEvents.test.ts
  • src/lib/litegraph/src/subgraph/SubgraphIOSlotLinks.test.ts
  • src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts

Replace weak negative assertions with explicit call-name filtering
to catch false passes. Add docstrings to inner bridge functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/core/canvas/links/useSubgraphDragBridge.ts (1)

70-75: Reuse a single adapter per drag session instead of recreating it per frame/event.

createLinkConnectorAdapter() is called on Line 70, again on Lines 117-118, and each RAF tick on Lines 181-182. Capturing one adapter for the active drag reduces churn and keeps candidate resolution/connect decisions consistent within the same drag session.

♻️ Proposed refactor
 export function useSubgraphDragBridge() {
@@
   function setupBridge(lgCanvas: LGraphCanvas): () => void {
     const linkConnector: LinkConnector = lgCanvas.linkConnector
     let teardownDrag: (() => void) | undefined
+    let activeAdapter: ReturnType<typeof createLinkConnectorAdapter> | null = null
     let isBridgeDrag = false
@@
       const adapter = createLinkConnectorAdapter()
       if (!adapter) return
+      activeAdapter = adapter
@@
-      teardownDrag = startPointerTracking(lgCanvas, linkConnector)
+      teardownDrag = startPointerTracking(lgCanvas, linkConnector, adapter)
     }
@@
-      const adapter = createLinkConnectorAdapter()
-      if (!adapter) return
+      const adapter = activeAdapter
+      if (!adapter) return
@@
     const onReset = () => {
       if (!isBridgeDrag) return
@@
       isBridgeDrag = false
+      activeAdapter = null
       endDrag()
     }
@@
       teardownDrag?.()
       teardownDrag = undefined
+      activeAdapter = null
       if (isBridgeDrag) {
@@
   function startPointerTracking(
     lgCanvas: LGraphCanvas,
-    linkConnector: LinkConnector
+    linkConnector: LinkConnector,
+    adapter: NonNullable<ReturnType<typeof createLinkConnectorAdapter>>
   ): () => void {
@@
-      const adapter = createLinkConnectorAdapter()
-      if (!adapter) return
       const graph = adapter.network

Also applies to: 108-109, 117-123, 181-184

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/core/canvas/links/useSubgraphDragBridge.ts` around lines 70 -
75, The code currently calls createLinkConnectorAdapter multiple times during a
drag session (e.g., where adapter and renderLink are captured), causing churn
and inconsistent candidate resolution; change this to instantiate a single
adapter when the drag session starts (store it on a stable ref/state inside
useSubgraphDragBridge or the startDrag handler), reuse that stored adapter and
its renderLinks (e.g., renderLink) in all subsequent handlers/RAF ticks, and
only recreate or dispose the adapter when the drag ends or is cancelled so all
calls no longer call createLinkConnectorAdapter repeatedly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/core/canvas/links/useSubgraphDragBridge.ts`:
- Around line 70-75: The code currently calls createLinkConnectorAdapter
multiple times during a drag session (e.g., where adapter and renderLink are
captured), causing churn and inconsistent candidate resolution; change this to
instantiate a single adapter when the drag session starts (store it on a stable
ref/state inside useSubgraphDragBridge or the startDrag handler), reuse that
stored adapter and its renderLinks (e.g., renderLink) in all subsequent
handlers/RAF ticks, and only recreate or dispose the adapter when the drag ends
or is cancelled so all calls no longer call createLinkConnectorAdapter
repeatedly.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 772cfe8 and 12ddc66.

📒 Files selected for processing (2)
  • src/lib/litegraph/src/subgraph/SubgraphIOSlotLinks.test.ts
  • src/renderer/core/canvas/links/useSubgraphDragBridge.ts

@christian-byrne

Copy link
Copy Markdown
Contributor

Rebased onto main and addressed CodeRabbit feedback in #9838:

  • Fixed unconditional canvas dirty during stable hover (perf)
  • Resolved merge conflict in SlotConnectionDot.vue (tailwind class ordering)
  • The duplicate raf.flush() was already fixed in your second commit 👍

Great work on this @artokun — the bridge composable approach is clean and well-tested. 🎉

@christian-byrne christian-byrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean architecture bridging canvas and Vue pointer state. CodeRabbit nitpick addressed in adopted PR #9838. Tests look good.

@artokun

artokun commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one out since the work is continuing in #9838 on the updated branch. Please follow that PR for the active review and any follow-up changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subgraph socket connection missing visual feedback

2 participants