fix(scroll): read initialScrollIndex offset after layout recompute#2133
Merged
naqvitalha merged 2 commits intomainfrom Mar 4, 2026
Merged
fix(scroll): read initialScrollIndex offset after layout recompute#2133naqvitalha merged 2 commits intomainfrom
naqvitalha merged 2 commits intomainfrom
Conversation
In applyInitialScrollAdjustment(), the scroll offset for the target initialScrollIndex item was read before recomputeLayouts() ran. The recompute re-estimates unmeasured items with updated average heights, which shifts the target item's y position. The stale offset caused a mismatch between the EngagedIndicesTracker's scroll position and the actual item positions, resulting in blank screens or overlapping items when initialScrollIndex was set with variable-height items. Move the offset read to after recomputeLayouts() so the scroll offset always reflects the target item's actual position. Also fixes a minor operator precedence issue in the nullish coalescing fallback. Includes a fixture repro screen (OverlapRepro) with 200 variable-height items (40-500px) and initialScrollIndex=50. Fixes #1797
tmgsca
approved these changes
Mar 4, 2026
7312445 to
9c199f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
initialScrollIndexis set and items have highly variable heights, items would overlap or the screen would appear blank. The root cause was inapplyInitialScrollAdjustment()— the scroll offset for the target item was captured beforerecomputeLayouts(0, initialScrollIndex)ran. The recompute re-estimates unmeasured items with updated average heights (which shift as real measurements come in), changing the target item's y position. The stale offset created a mismatch between the EngagedIndicesTracker's scroll position and actual item positions, causing the wrong items (or none) to be rendered during progressive rendering.The fix moves the offset read to after the recompute so the scroll offset always reflects the target item's actual position. Also fixes a minor operator precedence issue in the nullish coalescing fallback (
initialItemOffset ?? 0 + this.firstItemOffsetwas evaluated asinitialItemOffset ?? (0 + this.firstItemOffset)).Fixes #1797
Reviewers' hat-rack 🎩
RecyclerViewManager.ts— focus on whether reading the offset afterrecomputeLayoutsis always correct, including for theelsebranch (noinitialScrollIndex).ListHeaderComponent(non-zerofirstItemOffset), andmaintainVisibleContentPosition.startRenderingFromBottom.Test plan
yarn test— 183 tests)yarn type-check)yarn lint)initialScrollIndex=50now correctly starts at Item 50initialScrollIndex=25) or HorizontalList (initialScrollIndex=2)