Skip to content

Guard FlashList scroll viewability path before the first layout - #104826

Merged
mountiny merged 2 commits into
mainfrom
claude-flashListScrollBeforeLayout
Oct 26, 2026
Merged

mountiny merged 2 commits into
mainfrom
claude-flashListScrollBeforeLayout

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Stops the iOS HybridApp crash LayoutManager is not initialized, window size is unavailable, thrown from FlashList's onScroll (Sentry APP-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's onScroll calls recordInteraction() → updateViewableItems(). That reads getWindowSize() before it checks whether the list has any viewability listeners, so even lists with no viewability callbacks (like Workspaces_List) throw.

What this changes: Patch 002 now also guards the scroll/viewability path it leaves without a layout manager:

  1. ViewabilityManager.updateViewableItems returns early when there are no viewability listeners or !rvManager.hasLayout(), before calling getWindowSize().
  2. RecyclerViewManager.recordInteraction returns early when !hasLayout(). hasInteracted stays unset until the list can measure anything, so viewabilityConfig.waitForInteraction still works on the next scroll.
  3. RecyclerViewManager.computeItemViewability returns early when !hasLayout(). This covers lists with onViewableItemsChanged, which would otherwise throw from computeVisibleIndices() on the same event.

Lists that already have a layout behave exactly as before. The patch 002 entry in patches/@shopify/flash-list/details.md is updated.

Unit tests: tests/unit/FlashListTest.tsx adds two tests on RecyclerViewManager with 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 for waitForInteraction.

AI tests run locally:

  • npm test -- tests/unit/FlashListTest.tsx: pass (3/3). The 2 new tests fail without the fix.
  • FlashList-dependent suites (TableTest, TableSelectionTest, BaseSelectionListTest, BaseSelectionListSectionsTest, SearchAutocompleteListTest, EmojiPickerMenuComponentTest, tests/unit/components/SelectionList): pass (12 suites, 188 tests).
  • All 16 @shopify/flash-list patches apply in order on a clean @shopify/flash-list@2.3.2 with patch-package's apply logic, and the result matches the patched node_modules.
  • npm run lint-changed, npm run typecheck, npm run spell-changed, npm run fmt (no changes), ./scripts/validatePatches.sh: pass.
  • Not run locally: the full npm test suite 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

  1. Open a workspace through a deep link (for example, /workspaces/<policyID>/overview), so the Workspaces list mounts hidden behind it.
  2. Go back to Workspaces. Verify the list renders all rows and scrolls normally.
  3. Open any chat and tap the composer so the keyboard is up.
  4. Background the app, bring it back, then switch between the bottom tabs quickly several times.
  5. Verify the app does not crash and no LayoutManager is not initialized error appears in the console.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go to Account > Troubleshoot and turn on Force offline.
  2. Relaunch the app without clearing the cache.
  3. Repeat steps 1-5 from the Tests section.
  4. Verify the lists render from cached data, the app does not crash, and no LayoutManager is not initialized error appears.

QA Steps

Same as tests. The crash was reported on iOS HybridApp, so please cover iOS: Native in particular.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

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.

Workspace Overview Workspaces list Rapid tab switching
Workspace Overview page Workspaces list after returning from Overview App stable after rapid tab switching
Offline: Workspaces (cached) Offline: Overview (cached) Offline: composer focused Offline: rapid tab switching
Workspaces list from cache while offline Workspace Overview from cache while offline Chat composer focused while offline App stable after rapid tab switching while offline
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

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>
@MelvinBot
MelvinBot requested a review from a team October 23, 2026 09:23
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch because linhvovan29546 doesn't have a fork of Expensify/App I can push to.

To take ownership of this branch and push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-flashListScrollBeforeLayout
git checkout -b claude-flashListScrollBeforeLayout upstream/claude-flashListScrollBeforeLayout
git push -u origin claude-flashListScrollBeforeLayout

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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I addressed the review feedback in 5adeba03:

  • Added a comment above the early updateViewableItems guard in patch 002. It explains why the guard repeats the upstream check, so a future FlashList bump doesn't drop it.
  • Noted the same thing in the patch 002 entry of patches/@shopify/flash-list/details.md.

The edited hunk applies cleanly to node_modules, and tests/unit/FlashListTest.tsx passes (3/3). I replied in the review thread.

@linhvovan29546

Copy link
Copy Markdown
Contributor

@MelvinBot the code looks good to me. Could you fill out the PR description before this is ready for review?

  • Tests: still the // TODO placeholder. Please add manual steps for the affected flow. For example:
    1. Open a workspace through a deep link (e.g. /workspaces/<policyID>/overview) so the Workspaces list mounts hidden behind it.
    2. Go back to Workspaces and verify the list renders all rows and scrolls normally.
    3. Open a chat, focus the composer so the keyboard is up, background the app and bring it back, then switch tabs quickly.
    4. Verify there's no crash and no LayoutManager is not initialized error in the console.
  • Offline tests: please add steps. For example, turn on Force offline, relaunch the app, repeat the steps above, and verify the lists render from cached data with no errors.
  • QA Steps: still the // TODO placeholder. "Same as tests" is fine if QA can follow the Tests section.
  • Screenshots/Videos: please add recordings for all platforms (Android, iOS, mWeb, and Desktop).

@MelvinBot

MelvinBot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ⚠️ partial

I filled out Tests, Offline tests, and QA Steps in the PR description, and added Android: Native screenshots. On the Android emulator, the app did not crash or show an error overlay in any step I could run. The emulator could not open a real deep link, background the app, or fully relaunch it, so those steps and the iOS, mWeb, and Desktop recordings still need linhvovan29546.
App stable after rapid tab switching while offline

Step Status
Open a workspace through a deep link to /workspaces/<policyID>/overviewThe emulator could not send a real deep link. Tapping the link in a chat opened Chrome, because the dev build is not verified for that host. In-app navigation to Overview worked, but it does not reproduce the hidden first mount.
Workspace Overview page
❌
Go back to Workspaces: the list renders all rows and scrolls normallyThe list rendered the workspace row and stayed responsive while scrolling. No crash.
Workspaces list after returning from Overview
✅
Focus the composer, background and foreground the app, switch tabs quickly: no crashThe composer focused and quick tab switching caused no crash. The emulator could not background the app, so that part was not tested.
App stable after rapid tab switching
⚠️
No "LayoutManager is not initialized" error during steps 1-3No crash or error overlay appeared. The tester could not search the raw logcat for the exact string.
⚠️
Force offline, relaunch, repeat steps 1-3: lists render from cache with no errorsWith Force offline on and the cache intact, Workspaces, Overview, the chat composer, and tab switching all worked from cached data with no crash. The only restart option, "Clear cache and restart", also clears the cache, so the list was empty right after it. This is expected.
Force offline enabled
App after restart while offline
Workspaces empty after cache clear while offline
Workspaces list from cache while offline
Workspace Overview from cache while offline
Chat composer focused while offline
App stable after rapid tab switching while offline
⚠️

view run · view recording

@linhvovan29546

Copy link
Copy Markdown
Contributor

@MelvinBot Make PR ready for review

@MelvinBot
MelvinBot marked this pull request as ready for review October 26, 2026 14:01
@melvin-bot
melvin-bot Bot requested a review from linhvovan29546 October 26, 2026 14:01
@MelvinBot

Copy link
Copy Markdown
Contributor Author

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.


view run

@melvin-bot
melvin-bot Bot removed the request for review from a team October 26, 2026 14:01
@melvin-bot

melvin-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

@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]

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T14:04:48.838607Z 5adeba0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@linhvovan29546

linhvovan29546 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-10-26.at.21.07.03.mov
Android: mWeb Chrome
Screen.Recording.2026-10-26.at.21.05.33.mov
iOS: HybridApp
Screen.Recording.2026-10-26.at.21.09.23.mov
iOS: mWeb Safari
Screen.Recording.2026-10-26.at.21.04.09.mov
MacOS: Chrome / Safari
Screen.Recording.2026-10-26.at.21.02.20.mov

@melvin-bot
melvin-bot Bot requested a review from mountiny October 26, 2026 14:12
@mountiny
mountiny merged commit e731b9b into main Oct 26, 2026
53 of 56 checks passed
@mountiny
mountiny deleted the claude-flashListScrollBeforeLayout branch October 26, 2026 22:30
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.24-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 cancelled 🔪
🍎 iOS 🍎 cancelled 🔪

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.5.24-8 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants