Skip to content

fix: Flex items reordered to wrong places around line wraps and fixed items - #655

Draft
MatiPl01 wants to merge 7 commits into
mainfrom
fix/flex-reorder-strategy
Draft

MatiPl01 wants to merge 7 commits into
mainfrom
fix/flex-reorder-strategy

Conversation

@MatiPl01

@MatiPl01 MatiPl01 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Description

Fixes several cases in which the Sortable.Flex sort strategy and the layout disagreed about where items wrap, which made the dragged item jump to a wrong place, the order flip back and forth with the finger at rest, or, with a fixed-order item at the end, the order itself break:

  • the index of an item moved to a following line was off by one. With a fixed-order last item the target went past the end of the list, the fixed item was overwritten and another key was duplicated (onDragEnd then returned an order with a hole),
  • the rounding tolerance used when wrapping lines was not used by the strategy, so for lines filled exactly by items with fractional sizes it expected a wrap that the layout did not make,
  • an item wider than half of its line could not be dragged toward the end of that line (its size was counted twice),
  • a first item wider than the container was preceded by an empty line (the layout was shifted down by the row gap), and the strategy wrapped such an item even at the start of a line.

One commit per case. They are in one PR because each of them alone leaves the others visible in the same drags (and they touch the same few lines).

Known limitation: an item dragged to a line that ends with a fixed-order item is not moved while the pointer is over or past that fixed item (it has to be dropped before it). On main some of these drags moved the item, by accident of the size check removed here, and others broke the order.

Testing

9 new jest tests, 7 fail on main (the other two pin the rule that the first item of a line never wraps). Randomized drags through the real component and strategy: no broken order, no flipping and no out of range target on this branch (numbers for main in the file below).

Evidence
Tests on main before-test-on-main.txt
Tests with the fix after-test-with-fix.txt
Randomized drags, main vs this branch fuzz-results.txt

@MatiPl01 MatiPl01 self-assigned this Nov 25, 2026
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
react-native-sortables-docs Ignored Ignored Preview Nov 26, 2026 4:14pm UTC

- an item whose walk along a line ended on a fixed item was not moved at all, it now takes the closest free slot
- an item could not move to the last line when only fixed items followed its slot there
- the place of the active item in its line is read from the layout, which can have one line less than expected once the item is taken out
- the check for the line above includes the gap and lets an item wider than the container start a line, as the layout does
…ed lines"

With fixed items the order could flip back and forth with the pointer at rest, and with gaps an item could end two lines away from the pointer. This reverts commit 7809b68.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant