Fix VirtualizedList ignoring initialScrollIndex when scroll event arrives with offset=0 #55393
+393
−3
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.
Summary
Fixes a race condition in VirtualizedList where
initialScrollIndexis ignored when a scroll event withoffset=0arrives before the native scroll completes.The Problem:
When
initialScrollIndex > 0(e.g., 331), a scroll event withoffset=0could arrive before the native scroll completes. This would:pendingScrollUpdateCountto 0_adjustCellsAroundViewportto recalculate the render window using stale scroll metrics (offset=0)initialScrollIndexThe Fix:
Added a guard in
_onScroll()to only decrementpendingScrollUpdateCountwhen:initialScrollIndexis null or ≤ 0 (existing behavior), ORoffset > 0(valid scroll position received)This prevents the race condition where stale scroll metrics cause incorrect rendering.
Changelog:
[General] [Fixed] - Fix VirtualizedList ignoring initialScrollIndex when scroll event with offset=0 arrives before native scroll completes
Test Plan
Added two new test cases that reproduce the race condition:
"does not render items at index 0 when initialScrollIndex is large and scroll event arrives with offset 0"- Tests vertical list"correctly renders at large initialScrollIndex for horizontal list"- Tests horizontal listBoth tests:
initialScrollIndex=331offset=0(reproducing the race condition)Before fix: Tests FAIL - items 0-4 render
After fix: Tests PASS - items around 331 remain rendered
All existing VirtualizedList tests continue to pass (76/78, 2 skipped)
Test commands: