Skip to content

fix: node library drag drop to add node appears in wrong place in firefox#12419

Draft
pythongosssss wants to merge 2 commits into
mainfrom
pysssss/fix-firefox-drag-coords
Draft

fix: node library drag drop to add node appears in wrong place in firefox#12419
pythongosssss wants to merge 2 commits into
mainfrom
pysssss/fix-firefox-drag-coords

Conversation

@pythongosssss
Copy link
Copy Markdown
Member

@pythongosssss pythongosssss commented May 22, 2026

Summary

Firefox can give invalid drag coordinates causing incorrect drop position (https://bugzilla.mozilla.org/show_bug.cgi?id=1773886)
I was unable to consistently recreate this issue and it only happened in Firefox, so not a candidate for e2e tests.

Changes

  • What:
  • store position on dragover which looks to reliably report the correct position and use that value on drop

Screenshots (if applicable)

dragandbad.mp4

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

useNodeDragToCanvas records native dragover client coordinates (ignoring (0,0)), registers a document dragover listener, clears tracking on cancel, and prefers tracked coordinates when placing nodes on native drop; tests validate tracked-coordinate preference, fallbacks, ordering, and clearing.

Changes

Native drag position tracking

Layer / File(s) Summary
Position tracking infrastructure and listener setup
src/composables/node/useNodeDragToCanvas.ts
Adds lastNativeDragPosition and trackNativeDragPosition (ignores (0,0)), registers a document dragover listener in setupGlobalListeners, removes it in cleanupGlobalListeners, and resets the tracked position in cancelDrag.
Drop position resolution using tracked coordinates
src/composables/node/useNodeDragToCanvas.ts
handleNativeDrop places nodes using the most-recent lastNativeDragPosition when available, otherwise falls back to the provided clientX/clientY drop arguments.
Test coverage for native drag position tracking
src/composables/node/useNodeDragToCanvas.test.ts
Adds tests that simulate dragover events and assert preference for tracked coordinates over drop args, ignoring zeroed (0,0) events, fallback behavior when no dragover occurred, ignoring dragover before startDrag, and clearing tracked position between drags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Comfy-Org/ComfyUI_frontend#12194: Also modifies how drop coordinates are determined for placing created nodes; that PR updates addDropHandler while this PR adds native dragover-based tracking.

Suggested labels

size:S

Suggested reviewers

  • AustinMroz
  • dante01yoon

Poem

🐰 In a flutter of paws and tethered thread,
I chase the cursor where the pixels spread.
Ignore the zeros that pretend to lead,
Track every hop, each honest seed.
Then drop the node where true coords tread.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore (reviewers only)

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
End-To-End Regression Coverage For Fixes ❌ Error PR title contains "fix:" and changes src/ code without adding browser_tests/ changes. PR lacks concrete explanation for omitting E2E regression test. Add a Playwright regression test under browser_tests/ for drag-and-drop node placement, or add explicit explanation in PR description of why E2E testing is impractical.
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: addressing incorrect node placement during drag-and-drop in Firefox by improving drag coordinate tracking.
Description check ✅ Passed The description covers the problem (Firefox invalid drag coordinates), the solution (store position on dragover), and includes a video demonstration, but lacks explicit detail in the 'What' section and is missing the template's 'Review Focus' section.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Adr Compliance For Entity/Litegraph Changes ✅ Passed Check does not apply: changed files are in src/composables/node/, outside the ADR compliance scope of src/lib/litegraph/, src/ecs/, and entity-related files.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pysssss/fix-firefox-drag-coords

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
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

🎨 Storybook: ✅ Built — View Storybook

Details

⏰ Completed at: 05/22/2026, 03:08:48 PM UTC

Links

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

🎭 Playwright: ✅ 1636 passed, 0 failed · 2 flaky

📊 Browser Reports
  • chromium: View Report (✅ 1617 / ❌ 0 / ⚠️ 1 / ⏭️ 5)
  • chromium-2x: View Report (✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • chromium-0.5x: View Report (✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • mobile-chrome: View Report (✅ 16 / ❌ 0 / ⚠️ 1 / ⏭️ 0)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/composables/node/useNodeDragToCanvas.test.ts`:
- Around line 460-544: Add a new test in the "native drag position tracking"
suite that verifies dragover events fired before a native drag is started do not
affect later handleNativeDrop coordinates: call setupGlobalListeners(),
fireDrag(...) to simulate a pre-start dragover, then startDrag(mockNodeDef,
'native'), call handleNativeDrop(...) with known coords, and assert
mockConvertEventToCanvasOffset was called with the handleNativeDrop
clientX/clientY (e.g., {clientX: 300, clientY: 300}); reference
helpers/useNodeDragToCanvas functions startDrag, setupGlobalListeners,
handleNativeDrop and the local fireDrag helper when locating where to add the
test.

In `@src/composables/node/useNodeDragToCanvas.ts`:
- Around line 23-26: trackNativeDragPosition currently always sets
lastNativeDragPosition on every dragover causing stale coordinates to be used by
handleNativeDrop; modify trackNativeDragPosition to only set
lastNativeDragPosition when a native drag is actually in progress (e.g., when
e.dataTransfer exists and its types indicate a dragged payload) and otherwise
clear/reset lastNativeDragPosition (e.g., null/undefined) so stale positions are
not used; apply the same guarding/reset logic to the other native-drag handlers
referenced in this file (the other dragover/drop helpers around the
handleNativeDrop flow) so handleNativeDrop reads a valid current position or
falls back safely.
🪄 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: 9f79b7d6-9078-4d2f-bb52-fa4eebdec1fd

📥 Commits

Reviewing files that changed from the base of the PR and between 7b4fef5 and 8d41e3e.

📒 Files selected for processing (2)
  • src/composables/node/useNodeDragToCanvas.test.ts
  • src/composables/node/useNodeDragToCanvas.ts

Comment thread src/composables/node/useNodeDragToCanvas.test.ts
Comment on lines +23 to +26
function trackNativeDragPosition(e: DragEvent) {
if (e.clientX === 0 && e.clientY === 0) return
lastNativeDragPosition.value = { x: e.clientX, y: e.clientY }
}
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard/reset tracked native coordinates to prevent stale drop positions.

lastNativeDragPosition is currently updated for any document dragover, even when no native node drag is active. That stale value is then preferred in handleNativeDrop, which can place a node at an unrelated prior drag location.

💡 Suggested fix
 function trackNativeDragPosition(e: DragEvent) {
+  if (!isDragging.value || dragMode.value !== 'native') return
   if (e.clientX === 0 && e.clientY === 0) return
   lastNativeDragPosition.value = { x: e.clientX, y: e.clientY }
 }
 ...
 export function useNodeDragToCanvas() {
   function startDrag(nodeDef: ComfyNodeDefImpl, mode: DragMode = 'click') {
     isDragging.value = true
     draggedNode.value = nodeDef
     dragMode.value = mode
+    lastNativeDragPosition.value = null
   }

Also applies to: 113-117, 119-123

🤖 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/composables/node/useNodeDragToCanvas.ts` around lines 23 - 26,
trackNativeDragPosition currently always sets lastNativeDragPosition on every
dragover causing stale coordinates to be used by handleNativeDrop; modify
trackNativeDragPosition to only set lastNativeDragPosition when a native drag is
actually in progress (e.g., when e.dataTransfer exists and its types indicate a
dragged payload) and otherwise clear/reset lastNativeDragPosition (e.g.,
null/undefined) so stale positions are not used; apply the same guarding/reset
logic to the other native-drag handlers referenced in this file (the other
dragover/drop helpers around the handleNativeDrop flow) so handleNativeDrop
reads a valid current position or falls back safely.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@             Coverage Diff             @@
##             main   #12419       +/-   ##
===========================================
- Coverage   74.58%   60.03%   -14.55%     
===========================================
  Files        1529     1417      -112     
  Lines       92743    72540    -20203     
  Branches    25373    20154     -5219     
===========================================
- Hits        69169    43551    -25618     
- Misses      22725    28516     +5791     
+ Partials      849      473      -376     
Flag Coverage Δ
e2e ?
unit 60.03% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/composables/node/useNodeDragToCanvas.ts 100.00% <100.00%> (+1.94%) ⬆️

... and 1027 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant