fix(layout): skip layout updates when container size is 0x0#2269
Open
sharabai wants to merge 1 commit intoShopify:mainfrom
Open
fix(layout): skip layout updates when container size is 0x0#2269sharabai wants to merge 1 commit intoShopify:mainfrom
sharabai wants to merge 1 commit intoShopify:mainfrom
Conversation
b09e407 to
e53ef80
Compare
Author
|
CLA is signed. |
e53ef80 to
b1347f3
Compare
Author
|
@naqvitalha could you take a look at this PR when you have some free time on your hands? |
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 #2231
When FlashList is mounted inside a screen rendered by
@react-navigation/stackon web, pushing a new screen on top of it transiently measures FlashList's container as0x0. The two layoutuseLayoutEffects inRecyclerViewthen run with those bogus dimensions: the first overwrites the window/layout params with zeros, and the second walks everyviewHolderRefand rewrites item layouts. The downstream effect is that everyrenderItemre-runs — including offscreen items — which defeats recycling and causes the perf regression in the linked Snack repro.This PR adds two early returns inside
src/recyclerview/RecyclerView.tsx:0x0, store that size incontainerViewSizeRefand bail out before callingrecyclerViewManager.updateLayoutParams(...).containerViewSizeRef.currentis0x0, bail out before iteratingrefHolderand rewriting layouts.Once the screen is brought back into view and the container regains a non-zero size, the normal layout path resumes on the next layout pass — no items are dropped or re-mounted.
This is the same patch Expensify currently ships against
@shopify/flash-list@2.3.0for the same root cause discussed in #1816, and it removes the need for consumers to remember to toggle a Navigator-level workaround at every call site.Reviewers' hat-rack 🎩
containerViewSizeRef.current = outerViewSizebefore bailing, so the second effect can detect the0x0state.mainusing the Snack from the issue, then re-run against this branch and verify offscreen items stop re-rendering when a stack screen is pushed on top.Screenshots or videos
After-fix recording:
fixed.navigation.mp4