Repository navigation
fix(sortable): hold the post-drop flush while a touch is down in the list - #378
LunatiqueCoder wants to merge 34 commits into
Conversation
The data-change reset cleared the committed order but kept the drag's pending order and start/display indices, which index the old data. finalizeDrag then mapped them onto the new data and sent onReorder with one item lost. When the data really changes during a row drag, drop the pending move so the drag ends as a cancel: the row snaps back to its slot in the new data and no onReorder fires. Example: "Add a row in 1 s" on the reorderable list screen.
…k by the row's key
…after a data change The no-movement early return snapped to the dragged cell. In an index-keyed list (DraxList) that cell shows another row after a mid-drag data change. Use the key-based snap target there too, only when the data changed (the drag's indices were cleared). From [drax] Coder (bot).
A refetch (new array, same keys) during a row drag fell through the external-change reset and zeroed the shifts, so rows that had slid aside jumped back under the hover. Update stableData and return early instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sortable lists sent onReorder from finalizeDrag, one frame after the snap animation (about 350 ms after release). 0.11 reordered at release, and apps that update slot state from onReorder showed stale values for the whole snap. handleInternalDragEnd now sends onReorder at release (not for board columns, whose transfer is only known later) and commits the pending order, so the parent's echo matches it and waits for finalizeDrag. The visual commit (permanent shifts, flush) stays at snap end. finalizeDrag still sends onReorder when the release path did not. BREAKING CHANGE: onReorder fires at release instead of after the snap.
…er rows from data
…op order until snap end
…es at release Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… skew slots A same-key refetch re-renders every row. DraxView re-measures each one via measure(), which includes the in-flight shift transform, so a row's stored layout y (and the gap derived from it) went wrong and the drop landed one slot short. Keep a key's measurement while its list has a row drag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ight measure() includes a row's shift as rendered, which lags shiftsJSRef. DraxView used it for every x-0 row of a vertical FlatList, so re-renders (a refetch mid-drag, a drop's flush) stored shifted rows and skewed every slot boundary via computeItemGap. Count only an axis whose layout position is 0 as transform-positioned. SortableItem keeps a key's transform-including measurement during its list's drag, else re-measures once 2 frames on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reorder-at-release Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lands under drag 2 onReorder fires at release, so a controlled parent's echo renders during the snap. A drag that starts mid-snap finalizes the previous one in its handleDragStart, which requests the flush in a rAF. That rAF can fire before the new drag's first monitor update fills pendingOrderRef, so the echo was applied under the new drag: it started from a mix of the old and new order and dropped in the wrong slot. Port #334's dragActiveRef: set in SortableItem onDragStart, cleared in finalizeDrag, and flushIfReady bails while it is set. The flush lands after the new drag's finalize instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s right after it A drop's flush swaps the index-keyed cells, so row 0 (layout y 0) is measured by measure() with the previous row's shift, and SortableItem re-measures it 2 frames on. initPendingOrder set instantClearSV false at drag start, so a drag starting in those frames turned the instant clear into a spring. The re-measure caught row 0 mid-animation, keep held it for the whole drag, and every slot boundary was off (first onDragPositionChange to the last slot). Set instantClearSV false at the first live shift (computeShifts) instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reorder-at-release Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t measure() A FlatList row at layout 0,0 was measured with measure(), which includes the shift on screen. Right after an echo's flush, index-keyed cell 0 still shows the previous row's shift, so the row's key got the old visual y and the next drag's slots and shifts were off (drag 2 read slot 11, rows collapsed up). DraxView now passes the layout position with a transform-detected measurement; SortableItem uses it once the list has shown it places rows by layout. Also run sortableMeasureMirrors on fake timers so its follow-up measure rAF no longer outlives the test environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-drag # Conflicts: # CHANGELOG.md
… bot/coder-reorder-at-release
… drag test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bot/coder-reorder-at-release
…ack-to-back test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k-to-back test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bot/coder-reorder-at-release
…list Cells are index-keyed and a touch stays with the cell it began on. A flush landing between touch-down and the long-press activation rendered another item in the pressed cell, so the drag picked up the wrong row (pressed B at slot 0, dragged C at index 1). SortableContainer reports touches to useSortableList; flushIfReady waits while one is down and retries a frame after the last touch ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
LunatiqueCoder
left a comment
There was a problem hiding this comment.
🤖 posted by [drax] Reviewer, Ovidiu's review bot
real-touch at 3e82e55 (vs main fad042c): the window got smaller but it isn't closed yet.
repro: drag A 0→2, then long-press slot 0 (B) and move it down one, with a gap before drag 2. expected onDragStart index=0 item=B and final C B A D.
| gap | drag 2 starts after onSnapEnd | base | #378 |
|---|---|---|---|
| 0.15 | +40 ms | ok | ok 2/2 |
| 0.25 | +140–180 ms | grabs C | ok 2/2 |
| 0.35 (the original repro) | +240–257 ms | grabs C 5/5 | ok 5/5 |
| 0.40 | +307 ms | grabs C | grabs C 1/2 |
| 0.45 | +341–357 ms | grabs C | grabs C 4/4, also after a fresh launch |
| 0.50 | +404–410 ms | ok | grabs C 1/2 |
| 0.55–0.8 | +459–743 ms | ok | ok |
the stock /reorderable-list shows the same: gap 0.4 wrong 2/2, 0.45 and 0.5 wrong 1/3 each (once it lifted A).
so touch-downs before the snap ends are fixed, but a touch-down roughly 60–160 ms after onSnapEnd still binds to the old row. that's the residual race from the pr notes, and on real touch it's about 100 ms wide. it probably needs the pressed row re-checked at activation, or the flush held until the next frame commits. that's only a suggestion.
regressions pass: #348 back-to-back 2/2, #347 same-key refetch mid-drag 2/2, smokes. typecheck, lint, test green (167 tests).
…ush commits A touch hit-tested natively before the post-drop flush mounted can reach JS after flushIfReady ran, so #378's press hold misses it and the long press drags the index-keyed cell's new item (pressed B, dragged C). flushIfReady now keeps the pre-flush state. SortableItem's onTouchStart reports the touched cell; if the finger is outside the cell's layout rect but inside it moved by its old item's permanent shift, the flush is undone (the visual order is the same) and stays requested until the touch ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… rects Address Bugbot on #378: release the flush hold when the touches that began in the list end (nativeEvent.touches counts every touch on screen), and test a delayed touch against the old item's pre-flush rect so variable row heights and grid spans undo the flush too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fore its shift clear With variable row heights, the flush's Fabric commit can show a frame where each index-keyed cell has its new item at its new layout but the old item's shift. A press on B at the top then began on cell 2 and lifted A. Take the undo rects from the pre-flush measurements and the container origin, and make the cell non-draggable until that touch ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LunatiqueCoder
left a comment
There was a problem hiding this comment.
🤖 posted by [drax] Reviewer, Ovidiu's review bot
not merge-ready at 3a01b2b. native ios passes, but android and all three web targets fail. each web run used main 4e93328 as the control, with n=5 per gap.
- native ios: pass. on /reorderable-list, back-to-back drags never lifted the just-dropped A (0/30), zz-ctl passed 14/14 and tap 3/3, and a blocked press held for 2 s never activated (16/16)
- native android: intermittent fail. on zz-ctl, drag 2 lifted the just-dropped A in 3 of 67 runs, all in one metro session, with drag 2 starting about 120 ms after snapEnd (trace
onDragStart index=2 item=A, finalB A C D). b422775 had 0 of 28 here. on the variable-height /reorderable-list, B lifted correctly 47/47. the new blocked-cell branch never triggered on android - desktop chromium (mouse): fail. on zz-ctl the right row lifted only 7/30 (C lifted 23/30). on /reorderable-list A lifted 6/45, close to main (5/27), so this doesn't fix the mouse path
- ios safari: fail, and it's worse than main. on /reorderable-list, B lifts but the drop never commits in 25/45 runs, and the list goes blank mid-drag in 6/45. main shows neither. zz-ctl passes 29/30
- chromium mobile emulation (with #381): fail. the list goes blank mid-drag in 14/45 runs, every one of them a deferred flush. main with #381 never goes blank
the blank list and the drop that never commits only show up on the web build, and only when the post-drop flush is deferred while a touch is down. this looks like the deferred flush going stale or never running on react-native-web. ci is green, and there are no new bugbot comments on 3a01b2b.
…-index # Conflicts: # CLAUDE.md
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fc545b6. Configure here.
| const onTouchCancel = (event: GestureResponderEvent) => { | ||
| draxViewProps?.onTouchCancel?.(event); | ||
| endTouches(event); | ||
| }; |
There was a problem hiding this comment.
Missed touch end holds flush forever
Medium Severity
listTouchesRef only shrinks in onTouchEnd / onTouchCancel, and setPressActive(false) runs only when that set is empty. There is no reset on unmount, drag start, or finalizeDrag. If RNGH or a responder steal drops the cancel (common with nested GestureDetectors), the identifier stays in the set. Later touches cannot empty it, pressActiveRef stays true, and flushIfReady never applies, so the list remains on permanent shifts.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit fc545b6. Configure here.


🤖 From [drax] Coder (bot).
Based on main after #348 (
fad042c). Head is3e82e55(fix66babd0plus a clean merge of main).Bug (found by Reviewer in a real-touch run; also on main 93fad36)
In a controlled
DraxList, start a drag about 200–410 ms after the previous drop'sonSnapEnd, and the wrong row gets grabbed. You press B at slot 0, andonDragStartreportsindex=1 item=C. ExpectedC B A D, gotB A C D. On main, the same run can also committo=11.Root cause
DraxListcells are index-keyed (useStableKeyExtractor→__drax_${index},src/hooks/useSortableList.ts:32). A native touch stays with the cell view it began on.finalizeDrag(rAF) →flushVisualOrder→flushIfReady→setStableData(echo). That re-renders cell 1 as C at slot 1.{index: 1, originalIndex: 1}.Fix
SortableContainerforwards RNonTouchStart/onTouchEnd/onTouchCancel(which bubble up from the rows) to a new_internal.setPressActive. UserdraxViewPropstouch handlers are still called.flushIfReadyreturns early while a touch is down.handleDragStart, and the drag'sdragActiveRefmust be set first.setPressActivetoSortableListInternal(the_internaltype). It is not a public prop, and nothing else changes in the API.Tests
New
src/__tests__/SortableContainer.pressAcrossFlush.test.tsx. It uses the real dispatch +useSortableList+SortableContainer+SortableItem, with index-keyed cells likeDraxListand UI/JS FIFO queues.onDragStart {index: 0, item: 'B'}. Before the fix:{index: 1, item: 'C'}, the device log exactly.The tests fail before the fix (3 of 4) and all pass after. After merging main,
yarn typecheck,yarn lintandyarn test --no-watchman(22 suites / 167 tests) still exit 0.Not covered
flushIfReadydecides, before the Fabric mount) can still bind to the old cell. The window is the flush's render+mount time, not the 250 ms long-press window.onTouch*events fire only for touch input.zz-ctl, mode none,hiddrag.py --pts '100,192 100,312' --hold 0.4 --steps 10 --step 0.03 --end-hold 0 --then '100,192 100,252@1.5' --gap 0.35→ expectonDragStart index=0 item=Band finalC B A D.Trade-off at 3a01b2b (variable row heights)
For about one frame after a flush, a cell can render its new item's layout while still carrying the old item's shift. With variable heights the finger can land on that cell where the screen shows neither item. In that window the press is now ignored (
draggable={false}until the touch ends) rather than lifting the wrong row; the user just presses again. Reviewer's touch13 saw the wrong row lift 2/22 on /reorderable-list before this commit. The proper fix (commit the flush and clear the shift in one frame, so B lifts) is tracked for 1.2.1 in #383.Test:
SortableContainer.pressAcrossFlush.test.tsx› "a touch hit-tested on the frame the flush mounted does not drag a row it missed" (rows 80/50/60/80/50), fails on b422775. typecheck 0, lint 0, jest 180/180. Device re-run pending.Note
Medium Risk
Touches core post-drop reorder/flush timing and controlled-list data sync; logic is intricate but confined to sortable internals with broad new tests and no public API break.
Overview
Fixes wrong row grabbed in controlled sortable lists when a long press starts just after a drop: index-keyed cells can be re-filled during the post-echo
flushIfReadywhile the native touch still targets the original cell.SortableContainernow forwards bubbledonTouchStart/onTouchEnd/onTouchCancel, tracks touch identifiers, and drives new internalsetPressActive.flushIfReadyno longer applies while a list touch is down; it retries one frame after the last such touch ends.useSortableListsnapshots each flush inlastFlushRef.onItemTouchStart(fromSortableItemon native, using spatial index + finger position) can undo a flush when the press visually hit the pre-flush row, ordraggable={false}for one frame when variable heights make neither old nor new item match the finger.pendingShiftRestoreRefrestores permanent shifts when an undo happens after shifts were cleared.Adds
SortableContainer.pressAcrossFlush.test.tsxand documents the behavior in CHANGELOG / CLAUDE.md. No public API changes beyond internal_internalhelpers.Reviewed by Cursor Bugbot for commit fc545b6. Bugbot is set up for automated code reviews on this repo. Configure here.