Skip to content

Keep VirtualizedList's on-screen cells when estimates above them overlap them - #58940

Open
mozzius wants to merge 1 commit into
react:mainfrom
mozzius:virtualized-list-average-mismatch
Open

mozzius wants to merge 1 commit into
react:mainfrom
mozzius:virtualized-list-average-mismatch

Conversation

@mozzius

@mozzius mozzius commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary:

computeWindowedRenderLimits finds the visible cells by binary-searching estimated cell offsets, and an unmeasured cell is estimated at the current average cell length times its index. A spacer keeps the size it was rendered with, so once the average changes, the estimates for the cells in a spacer can overlap the rendered cells after it. After a large prepend at the top under maintainVisibleContentPosition, the prepended cells rendered above the spacer change the average before native's correction arrives, the corrected offset maps into the spacer, and the cells on screen are unmounted. This takes the visible range from the mounted cells' measured frames when the search disagrees with them about where the viewport starts. When estimates and measurements agree, nothing changes.

Fixes #58939. Repro: https://github.com/mozzius/virtualizedlist-average-mismatch-repro

Changelog:

[GENERAL] [FIXED] - Fix VirtualizedList unmounting the cells on screen when the estimates for a spacer above them overlap them

Test Plan:

🤖 Generated with Claude Code

…lap them

computeWindowedRenderLimits finds the visible cells by binary-searching
getCellMetricsApprox, which places an unmeasured cell at the current average
cell length times its index. A spacer keeps the size it was rendered with, so
once the average changes, the estimates for the cells in a spacer can overlap
the rendered cells after it. After a large prepend at the top under
maintainVisibleContentPosition, the prepended cells rendered above the spacer
change the average before native's correction arrives, the corrected offset
maps into the spacer, and the cells on screen are unmounted.

When the search disagrees with a mounted cell's measured frame about where
the viewport starts, use the mounted cells that cover the viewport.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 8, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 8, 2026

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VirtualizedList unmounts the visible row after a big prepend near the top: the window is computed from row estimates that no longer match the spacer

1 participant