Skip to content

fix(layout): prevent item overlap during fast scroll with dynamic heights#2196

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
fix/issue-2175-dynamic-height-overlap
Closed

fix(layout): prevent item overlap during fast scroll with dynamic heights#2196
github-actions[bot] wants to merge 1 commit intomainfrom
fix/issue-2175-dynamic-height-overlap

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Description

When FlashList items have dynamic heights and early items are measured with heights significantly different from the initial estimate, the layout recomputation only covers a limited range of items. The guard condition that decides whether to extend the recomputation checked only the very last item's position against the boundary, missing cases where items immediately after the recomputed range had stale positions going backwards. This broke the monotonic position ordering that the binary search relies on, causing items to overlap, jump, and collapse during fast scrolling.

The fix changes the guard to check the item immediately after the recomputed range instead of the last item, correctly detecting position discontinuities at the boundary and triggering full recomputation when needed.

Fixes #2175

Reviewers' hat-rack 🎩

Focus on the guard condition change in _recomputeLayouts in LayoutManager.ts. The key question is whether checking nextPos < endPos (position of item at endIndex+1 vs position of item at endIndex) is the right heuristic for all layout types (linear, grid, masonry). For grid layouts, items in the same row share the same y, so nextPos < endPos should only trigger across row boundaries when positions truly go backwards.

Test plan

  • Unit tests pass (yarn test)
  • Type check passes (yarn type-check)
  • Lint passes (yarn lint)
  • New test verifies monotonic positions after partial recomputation with growing heights
  • Verified on iOS simulator (agent-device timed out on CI)
  • No regressions on related screens

…ghts

When items have dynamic heights and the average height estimate grows,
the partial recomputation of layout positions creates a boundary where
items in the recomputed range shift forward while items beyond it keep
their old (lower) positions. The previous guard only checked the very
last item's position against the recomputed range boundary, which missed
cases where the immediately-next item had a stale position going
backwards. This broke the monotonic ordering that binary search relies
on, causing items to overlap and jump during fast scrolling.

Fix the guard to check the item immediately after the recomputed range
instead of the last item, detecting position discontinuities at the
boundary and triggering a full recomputation when needed.

Fixes #2175
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.

Dynamic item height causes items to overlap during fast scroll

1 participant