Skip to content

fix(scroll): maintain scroll position when prepending large items#2138

Open
naqvitalha wants to merge 8 commits intomainfrom
fix/scroll-maintenance-large-prepend
Open

fix(scroll): maintain scroll position when prepending large items#2138
naqvitalha wants to merge 8 commits intomainfrom
fix/scroll-maintenance-large-prepend

Conversation

@naqvitalha
Copy link
Collaborator

@naqvitalha naqvitalha commented Mar 6, 2026

Summary

  • When large items are prepended to a FlashList, the scroll correction mechanism needs multiple render passes to converge as unmeasured item heights settle. After the first correction pass, the anchor item could move outside the engaged indices window due to height estimation errors. The fallback full-data search was gated behind hasDataChanged, which was already false by the second pass — so the anchor was lost and scroll stayed wrong.
  • Adds an isRefiningCorrection flag that keeps subsequent correction passes able to locate the anchor item and update the internal scroll offset until convergence. The flag piggybacks on the existing ignoreScrollEvents timeout for cleanup.

Test plan

  • Open the "Prepend Maintain Scroll" example in the fixture app (or use the Expo Snack from the issue)
  • Verify that after prepending large items, the original (green) item remains visible
  • Verify the Chat example's "Add at Top" still maintains scroll position
  • yarn test — all 183 unit tests pass

Fixes #2136

When large items are prepended, the scroll correction needs multiple
passes to converge as unmeasured item heights settle. After the first
correction pass, the anchor item could move outside the engaged indices
window, and the fallback data search was gated behind hasDataChanged
which was already false. This caused the second correction pass to fail
to find the anchor, leaving the scroll at the wrong position.

Track an isRefiningCorrection flag that allows subsequent correction
passes to search the full data array for the anchor item and update
the internal scroll offset until the correction converges.

Fixes #2136
@naqvitalha naqvitalha requested a review from tmgsca March 6, 2026 23:49
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.

Scroll not maintained when prepending large elements

1 participant