Skip to content

Wait a frame between dragover and drop in the e2e drag helpers - #409

Merged
TrevorBurnham merged 3 commits into
jameskerr:mainfrom
melihozcan1:fix/e2e-frame-before-drop
Nov 29, 2026
Merged

TrevorBurnham merged 3 commits into
jameskerr:mainfrom
melihozcan1:fix/e2e-frame-before-drop

Conversation

@melihozcan1

@melihozcan1 melihozcan1 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #408. budget-spec.cy.js ("updates folder totals when an expense moves between folders") still failed on #407 after main, with #408 merged in, was merged into it (run). The assertion is the same as in every earlier failure: '📂Entertainment$0' where $60 was expected. The hydration race #408 fixed is real, but it wasn't the one CI kept losing. This is.

Cause: the spec fires dragover and then drop as back-to-back Cypress commands. Two react-dnd details make the result depend on whether an animation frame runs between them:

  • The HTML5 backend doesn't apply dragover right away. It schedules the hover for the next animation frame (scheduleHover → requestAnimationFrame). drop runs hover + drop synchronously.
  • dnd-core calls a drop target's hover() from inside the hover action creator, before the HOVER reducer stores the new pointer position. So monitor.getClientOffset() inside our hover returns the position from the previous hover.

If a frame runs between the commands, the dragover hover stores Entertainment's position, and the drop's hover reads it: the drop goes into the folder ✓. If no frame runs, the only stored position is the one from dragstart, which is the Internet row 7 rows up. computeDrop then resolves "above Entertainment", so Internet moves to the top level and Entertainment stays at $0 ✗.

Real drags aren't affected the same way, because browsers fire dragover on every frame before the release, so the stored position is at most a frame old.

Fix: a new cy.nextFrame() command waits one animation frame. The drag helper calls it between dragover and drop, the way a real drag gives dragover frames before release. Its frame callback is registered after the backend's, so the hover is stored by the time drop fires.

One shared helper: the four specs each had their own copy of the drag helper, and the copies had drifted apart. They're now one cy.dragAndDrop(src, dst, position) in support/commands.js. That gives the gmail drags a dragover too. Until now, their drops were placed by where the dragged row started (the dragstart position), not by where they were dropped, so two expected indices change: 2 → 3 and 11 → 12. Those two drops aim at the target row's bottom edge, because a leaf row's vertical center is exactly where a drop flips from above it to below it. With the page shifted down 0.6px, a center drop on Sent lands above it, while a bottom-edge drop still lands below.

Verification (throwaway specs, not committed):

  • Forced race: animation frames slowed to 1 s, so drop always lands before the dragover frame. The old helper fails 3/3 with exactly the CI message; the new helper passes 3/3.
  • Same-task repro without slowing frames: dragover + drop dispatched in one task fails 3/3 with the CI message, and one frame apart passes 3/3.
  • Real budget drag with the new helper: 30/30.
  • The four drag specs with the shared cy.dragAndDrop: 5/5 runs green, 21/21 tests each.

Checklist

  • Added a .changes/ entry describing the change (see .changes/README.md), or applied the skip-changelog label if it has no user-facing effect.
  • yarn lint, yarn fmt:check, and yarn workspace react-arborist test pass (warning-clean — see AGENTS.md).

No changeset: e2e only, nothing in modules/react-arborist/src. yarn workspace e2e: 22/22 locally.

Copilot AI balanced review requested due to automatic review settings November 28, 2026 22:12
@netlify

netlify Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

👷 Deploy request for react-arborist pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 19f134b

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@TrevorBurnham TrevorBurnham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the diagnosis checks out. I traced it in dnd-core 16.0.1: createHover calls hoverAllTargets (and therefore our hover) before it returns the HOVER action with the new clientOffset. So the hover that handleTopDrop runs reads whatever offset the previous hover stored. Without a frame in between, that's the dragstart offset. Waiting one frame so the scheduled dragover hover lands first is the right fix.

Two small suggestions inline, neither blocking. There's also a separate note below about the gmail helper.

Comment thread modules/e2e/cypress/support/commands.js Outdated
Comment on lines +34 to +35
// react-dnd applies a dragover on the next animation frame, so a drop fired in
// the same frame reads the pointer position from dragstart instead.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could the comment also say why the drop's own coordinates don't help? Anyone reading handleTopDrop will see it passes getEventClientOffset(e) and conclude the frame wait is unnecessary. Maybe something like:

// react-dnd applies a dragover on the next animation frame. On drop, it calls
// our hover() before storing the drop's own pointer position, so hover() reads
// the last stored one. Without a frame between dragover and drop, that's the
// dragstart position.

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.

Updated with your wording in bcc39b9.

const dataTransfer = new DataTransfer();
src.trigger("dragstart", { dataTransfer });
dst.trigger("dragover", { dataTransfer });
cy.nextFrame();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional: this helper now exists in four specs that have drifted apart (gmail's copy has no dragover). Would you move it into support/commands.js as cy.dragAndDrop(src, dst) next to nextFrame? Then the next timing fix only has to be made once. Fine as a follow-up if you'd rather keep this PR small.

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.

I'll keep this PR small and do it in a follow-up: one cy.dragAndDrop(src, dst) in support/commands.js, used by all four specs.

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.

Did it in this PR after all, in 19f134b: one cy.dragAndDrop(src, dst, position) in support/commands.js, used by all four specs.

@TrevorBurnham

Copy link
Copy Markdown
Collaborator

The gmail helper isn't flaky, since with no dragover there's no pending hover to race. But it does depend on the stale offset. With no dragover, the drop's hover() reads the dragstart offset, so each drop is placed by where the source row sits relative to the target. I checked by running the three gmail drags with this PR's helper (dragover + cy.nextFrame()):

Test Current helper With dragover + frame Asserted
Inbox → Sent index 2 (above Sent) index 3 (below Sent) 2
Starred → Social index 11 (above Social) index 12 (below Social) 11
Inbox → Social (blocked) index 0 index 0 0

So two of the three assertions encode where the dragstart position happens to land. If the helper ever gets a dragover (for example, if it moves into a shared cy.dragAndDrop), those two tests will fail. Not blocking for this PR, but worth a follow-up that adds dragover + cy.nextFrame() to the gmail helper and updates the expected indices to 3 and 12.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 08:37

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@melihozcan1

Copy link
Copy Markdown
Contributor Author

Thanks for checking. I'll fold it into the same follow-up as the shared cy.dragAndDrop, since moving gmail onto it is what adds the dragover.

One thing I'll handle there: Cypress fires at the row's exact vertical center, and for a leaf row measureHover picks above or below with y < height / 2. So 3 and 12 sit right on that boundary and could flip with sub-pixel layout. I'll aim those drops at the row's lower half instead of the center, so the expected index doesn't depend on rounding.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 17:03

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@melihozcan1

Copy link
Copy Markdown
Contributor Author

Done in this PR instead of a follow-up, in 19f134b. Gmail now uses the shared cy.dragAndDrop, so it gets dragover + cy.nextFrame(), and the two indices are now 3 and 12.

Those two drops aim at the row's bottom edge rather than its center. To check the boundary, I shifted the page down 0.6px: a center drop on Sent then lands above it (index 2), while a bottom-edge drop still lands below it (index 3). The blocked Inbox → Social drop still asserts 0.

@TrevorBurnham
TrevorBurnham merged commit b6424d5 into jameskerr:main Nov 29, 2026
2 checks passed
@TrevorBurnham

Copy link
Copy Markdown
Collaborator

Thanks!

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.

3 participants