Repository navigation
Guard FlashList scroll viewability path before the first layout - #104826
Conversation
Patch 002 skips 0x0 layouts, so a list can receive a native scroll event before it has a layout manager. FlashList's onScroll then called recordInteraction -> updateViewableItems -> getWindowSize, which threw 'LayoutManager is not initialized, window size is unavailable'. Return early from updateViewableItems, recordInteraction and computeItemViewability until the list has a layout. Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
|
I created this PR from an upstream branch because To take ownership of this branch and push updates, run: Then you can close this PR and open a new one from your fork. |
| }; | ||
| this.updateViewableItems = (newViewableIndices) => { | ||
| var _a; | ||
| + if (!this.shouldListenToVisibleIndices || !this.rvManager.hasLayout()) { |
There was a problem hiding this comment.
NAB: after this guard, the !this.shouldListenToVisibleIndices half of the upstream check a few lines below (if (listSize === undefined || !this.shouldListenToVisibleIndices)) can never be true anymore.
Keeping the upstream line untouched is fine for easier rebases, but could we add a short comment explaining why the check is duplicated here? Otherwise someone doing the next FlashList bump may "clean up" one of the two and drop this guard, bringing back the LayoutManager is not initialized, window size is unavailable crash:
// Check listeners and layout BEFORE getWindowSize(), which throws when there is no layoutManager (patch 002 skips 0x0 layouts)
if (!this.shouldListenToVisibleIndices || !this.rvManager.hasLayout()) {
return;
}There was a problem hiding this comment.
Done in 5adeba03. I added your comment above the guard and left the upstream line untouched.
I also noted it in the patch 002 entry of details.md: the later upstream check is redundant but kept for easier rebases, and the early guard must stay on the next FlashList bump.
tests/unit/FlashListTest.tsx still passes (3/3).
…heck Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
|
I addressed the review feedback in 5adeba03:
The edited hunk applies cleanly to |
|
@MelvinBot the code looks good to me. Could you fill out the PR description before this is ready for review?
|
|
@MelvinBot Make PR ready for review |
|
I marked this PR as ready for review. The PR Author Checklist is still unchecked. The iOS, mWeb, and Desktop recordings are still missing too. These come from the human co-author. |
|
@linhvovan29546 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-10-26.at.21.07.03.movAndroid: mWeb ChromeScreen.Recording.2026-10-26.at.21.05.33.moviOS: HybridAppScreen.Recording.2026-10-26.at.21.09.23.moviOS: mWeb SafariScreen.Recording.2026-10-26.at.21.04.09.movMacOS: Chrome / SafariScreen.Recording.2026-10-26.at.21.02.20.mov |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.24-1 🚀
|
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.5.24-8 🚀
Bundle Size Analysis (Sentry): |










Explanation of Change
Stops the iOS HybridApp crash
LayoutManager is not initialized, window size is unavailable, thrown from FlashList'sonScroll(SentryAPP-MHA).Why it happens: Our FlashList patch 002 (skip layout when hidden) returns early when a list first measures at 0×0, so FlashList never creates its
layoutManager. Upstream always creates it on the first layout. If a native scroll event arrives before the first real layout (for example, iOS adjusting the content inset with no user touch), FlashList'sonScrollcallsrecordInteraction()→updateViewableItems(). That readsgetWindowSize()before it checks whether the list has any viewability listeners, so even lists with no viewability callbacks (likeWorkspaces_List) throw.What this changes: Patch 002 now also guards the scroll/viewability path it leaves without a layout manager:
ViewabilityManager.updateViewableItemsreturns early when there are no viewability listeners or!rvManager.hasLayout(), before callinggetWindowSize().RecyclerViewManager.recordInteractionreturns early when!hasLayout().hasInteractedstays unset until the list can measure anything, soviewabilityConfig.waitForInteractionstill works on the next scroll.RecyclerViewManager.computeItemViewabilityreturns early when!hasLayout(). This covers lists withonViewableItemsChanged, which would otherwise throw fromcomputeVisibleIndices()on the same event.Lists that already have a layout behave exactly as before. The patch 002 entry in
patches/@shopify/flash-list/details.mdis updated.Unit tests:
tests/unit/FlashListTest.tsxadds two tests onRecyclerViewManagerwith no layout. Both fail on the unpatched code with the Sentry error, and pass with this change. The second test also checks that viewable items are still reported after the first layout, and that the early scroll does not count as the interaction forwaitForInteraction.AI tests run locally:
npm test -- tests/unit/FlashListTest.tsx: pass (3/3). The 2 new tests fail without the fix.TableTest,TableSelectionTest,BaseSelectionListTest,BaseSelectionListSectionsTest,SearchAutocompleteListTest,EmojiPickerMenuComponentTest,tests/unit/components/SelectionList): pass (12 suites, 188 tests).@shopify/flash-listpatches apply in order on a clean@shopify/flash-list@2.3.2with patch-package's apply logic, and the result matches the patchednode_modules.npm run lint-changed,npm run typecheck,npm run spell-changed,npm run fmt(no changes),./scripts/validatePatches.sh: pass.npm testsuite and the Storybook smoke test. The crash is native iOS only and was not reproduced on a device.Fixed Issues
$ #104502
PROPOSAL: #104502 (comment)
Tests
/workspaces/<policyID>/overview), so the Workspaces list mounts hidden behind it.LayoutManager is not initializederror appears in the console.Offline tests
LayoutManager is not initializederror appears.QA Steps
Same as tests. The crash was reported on iOS HybridApp, so please cover iOS: Native in particular.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screenshots from MelvinBot's emulator run (dev build). The emulator could not open a real deep link, background the app, or do a full relaunch, so those steps still need a human recording.
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari