Repository navigation
Wait a frame between dragover and drop in the e2e drag helpers - #409
Conversation
👷 Deploy request for react-arborist pending review.Visit the deploys page to approve it
|
TrevorBurnham
left a comment
There was a problem hiding this comment.
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.
| // 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. |
There was a problem hiding this comment.
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.| const dataTransfer = new DataTransfer(); | ||
| src.trigger("dragstart", { dataTransfer }); | ||
| dst.trigger("dragover", { dataTransfer }); | ||
| cy.nextFrame(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Did it in this PR after all, in 19f134b: one cy.dragAndDrop(src, dst, position) in support/commands.js, used by all four specs.
|
The gmail helper isn't flaky, since with no
So two of the three assertions encode where the dragstart position happens to land. If the helper ever gets a |
|
Thanks for checking. I'll fold it into the same follow-up as the shared One thing I'll handle there: Cypress fires at the row's exact vertical center, and for a leaf row |
…s drops at the row's bottom edge
|
Done in this PR instead of a follow-up, in 19f134b. Gmail now uses the shared 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. |
|
Thanks! |
Summary
Follow-up to #408.
budget-spec.cy.js("updates folder totals when an expense moves between folders") still failed on #407 aftermain, with #408 merged in, was merged into it (run). The assertion is the same as in every earlier failure:'📂Entertainment$0'where$60was expected. The hydration race #408 fixed is real, but it wasn't the one CI kept losing. This is.Cause: the spec fires
dragoverand thendropas back-to-back Cypress commands. Two react-dnd details make the result depend on whether an animation frame runs between them:dragoverright away. It schedules the hover for the next animation frame (scheduleHover→requestAnimationFrame).droprunshover+dropsynchronously.hover()from inside the hover action creator, before theHOVERreducer stores the new pointer position. Somonitor.getClientOffset()inside ourhoverreturns the position from the previous hover.If a frame runs between the commands, the
dragoverhover stores Entertainment's position, and the drop'shoverreads it: the drop goes into the folder ✓. If no frame runs, the only stored position is the one fromdragstart, which is the Internet row 7 rows up.computeDropthen 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
dragoveron 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 betweendragoveranddrop, the way a real drag givesdragoverframes before release. Its frame callback is registered after the backend's, so the hover is stored by the timedropfires.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)insupport/commands.js. That gives the gmail drags adragovertoo. Until now, their drops were placed by where the dragged row started (thedragstartposition), 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):
dropalways lands before thedragoverframe. The old helper fails 3/3 with exactly the CI message; the new helper passes 3/3.dragover+dropdispatched in one task fails 3/3 with the CI message, and one frame apart passes 3/3.cy.dragAndDrop: 5/5 runs green, 21/21 tests each.Checklist
.changes/entry describing the change (see.changes/README.md), or applied theskip-changeloglabel if it has no user-facing effect.yarn lint,yarn fmt:check, andyarn workspace react-arborist testpass (warning-clean — seeAGENTS.md).No changeset: e2e only, nothing in
modules/react-arborist/src.yarn workspace e2e: 22/22 locally.