fix(layout): skip measurement while web container is hidden - #2523
Open
HuuNguyen312 wants to merge 1 commit into
Open
HuuNguyen312 wants to merge 1 commit into
HuuNguyen312 wants to merge 1 commit into
Conversation
On web, a list inside a display:none container reads every size as 0. Measuring then overwrote real item heights with 0, so the engaged range covered the whole data set and every item rendered at once (e.g. ~6000 chat messages on logout). Skip container and item measurement while the container is hidden and record a zero container size so onLayout re-measures once it is shown.
This branch has not been deployed
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
Fixes #2522
On web, when a FlashList is mounted inside a container that becomes hidden (
display: none, e.g. an inactive screen/column kept mounted), every DOM size reads as0. If the list re-renders while hidden (data update, parent state change), the layout effects still run and:measureParentSizereturns a0 x 0window.measureItemLayoutreturnsheight: 0for every rendered item, overwriting the real measured heights.With all layouts collapsed to
y = 0, height = 0,getVisibleLayoutsreturns the entire data set as engaged, and the list mounts every item at once. In our chat app (~6,000 messages, inverted list) this froze the app on logout, when the chat screen is hidden but still mounted. Debug output captured at that moment:Fix
isViewHidden(view)tomeasureLayout.web.ts: the container is hidden when bothclientWidthandclientHeightare0. The native implementation always returnsfalse, so native behavior is unchanged.RecyclerView, skip the container-measurement and item-measurement layout effects while the container is hidden, keeping the last valid layouts.0 x 0container size so the existingonLayoutsize check sees a change once the container is shown again and triggers a fresh measurement.Reviewers’ hat-rack 🎩
display: none, then updatedatawhile hidden. Before: every item renders. After: no extra items render.isViewHiddenalways returnsfalse).isViewHidden(src/__tests__/measureLayout.web.test.ts).yarn testandyarn type-checkpass; ESLint is clean on the changed files.