Skip to content

Remove useOnyx loading status reads for collection keys and keys with default values - #105374

Merged
mountiny merged 7 commits into
Expensify:mainfrom
callstack-internal:VickyStash/refactor/104583-remove-always-loaded-keys
Nov 3, 2026
Merged

mountiny merged 7 commits into
Expensify:mainfrom
callstack-internal:VickyStash/refactor/104583-remove-always-loaded-keys

Conversation

@VickyStash

@VickyStash VickyStash commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This is the first cleanup batch after the no-onyx-loading-status lint rule. It removes useOnyx status reads that can never be loading once the app has started.

useOnyx reports loading in only two cases: before Onyx.init has loaded storage into the cache, or when a key has no cached value and an Onyx.merge for that key is still pending. Once startup is done, neither case applies to these keys:

  • Collection keys (POLICY, DOMAIN, RULE, BULK_ACTION, EXPORT_DOWNLOAD, WORKSPACE_CARDS_LIST, TRANSACTION, SHARED_NVP_PRIVATE_DOMAIN_MEMBER). Merges are queued under member keys, never under the collection key itself.
  • Keys with a default value in initialKeyStates (SESSION, ACCOUNT, MODAL, RECENT_SEARCHES). They always have a cached value.

All of these files mount after Onyx.init has finished, so each removed read was always loaded and each isLoadingOnyxValue call was always false. The PR deletes those checks, along with the metadata variables and any branches that only ran while loading.

This PR only includes files where every status read is one of these keys. The files drop out of the seatbelt baseline in both eslint.seatbelt.tsv and oxlint.seatbelt.tsv.

Fixed Issues

$ #104583
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Search

  1. Open the Search router (the search icon or Cmd/Ctrl+K).
    • Verify recent searches and recent chats show right away, without a skeleton flash.
    • Type a query and verify results filter, and that "No results found" appears for a query with no matches.
  2. In Search, open Filters > Workspace and verify the workspace list shows.
  3. In Search, start an export that shows the progress modal. Reload the page before it finishes and verify the export modal comes back and delivers the file.
  4. Open an expense from a list of several in Search and verify the previous/next arrows move between expenses and the counter is correct. Delete one sibling expense and verify the carousel drops it.
  5. Go to Reports/Search, open a query grouped by card (Group by > Card), and verify results and card feed names load without a stuck skeleton.

Workspace pickers

  1. As a member of several workspaces, create a report from the global create menu and verify the workspace selection list shows.
  2. Open an open expense report, choose "Change workspace" from the header menu, and verify the workspace list shows.
  3. Create a new workspace and verify the workspace name input on the confirmation form shows with the default name, and that the currency and plan type fields work.

Insights / workspace settings

  1. Open an Insights dashboard and verify the charts load. Change the workspace filter and verify the charts refresh.
  2. Go to Workspace > Rules > Expense defaults and open an existing merchant rule. Verify the rule fields load. Change the rule ID to an invalid one and verify the not-found page shows.

Account / settings

  1. Sign up with a new public-domain account and verify the onboarding modal shows and works.
  2. Go to Settings > Security > Two-factor authentication on an account without 2FA and verify the recovery codes step loads.
  3. As a normal user, verify product training tooltips and the marketing window can still show.

Offline tests

Same, as in Tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

Same, as in Tests

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 followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 followed the guidelines as stated in the Review Guidelines
  • 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 a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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

Search
search.mp4
search_pt2.mp4
ios_search.mp4
Workspace pickers
wp_web.mp4
ios_wp.mov
Insights / workspace settings
insights_web.mp4
insights_ios.mov
Account / settings
onboarding_web.mp4
tooltip_web.mp4

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/FullstoryInitHandler.tsx 73.33% <100.00%> (+2.74%) ⬆️
src/components/BulkActionStatusManager.tsx 85.29% <100.00%> (ø)
src/components/ExportDownloadStatusManager.tsx 95.12% <100.00%> (ø)
...nts/PopoverMenu/v2/content/useCloseOnModalCover.ts 100.00% <100.00%> (+7.69%) ⬆️
...ents/Search/FilterComponents/WorkspaceSelector.tsx 89.10% <100.00%> (ø)
src/components/Search/SearchAutocompleteList.tsx 89.88% <100.00%> (+0.39%) ⬆️
src/components/Search/index.tsx 70.99% <100.00%> (-0.11%) ⬇️
src/hooks/useCarouselTransactionIDs.ts 94.11% <100.00%> (ø)
src/hooks/useSearchLoadingState.ts 100.00% <100.00%> (ø)
src/hooks/useShouldSuppressPromotionalUI.ts 100.00% <100.00%> (ø)
... and 11 more
... and 18 files with indirect coverage changes

…ded-keys

# Conflicts:
#	config/oxlint/oxlint.seatbelt.tsv
#	src/pages/Insights/InsightsDashboard.tsx
@VickyStash

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

MelvinBot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review

One regression: the useSaveMarketingAttribution change. The other 21 source files look correct.

❌ useSaveMarketingAttribution runs before Onyx.init finishes

Expensify.tsx:72 calls this hook above the isOnyxMigrated gate at Expensify.tsx:293. So the PR's assumption that "all of these files mount after Onyx.init has finished" does not hold for this file. React renders while storage.getAll is still in flight, so useOnyx(SESSION) returns [undefined, {status: 'loading'}] on the first render.

After this PR, the effect at useSaveMarketingAttribution.ts:21-27 runs on that first commit:

  1. hasNonAnonymousSession is undefined, so saveMarketingAttribution(captured, false) writes MARKETING_ATTRIBUTION.
  2. hasHandledAttribution.current is now true, so the effect never re-runs once the real session loads.

As a result, a signed-in user who opens a link with UTM or gclid params gets attribution stored. That is the case the hasSession guard in saveMarketingAttribution exists to prevent. If they later sign out and a new account signs up on that device, the signup could be credited to a stale ad click.

Fix: Keep the isLoadingOnyxValue(sessionMetadata) check in this hook, and keep its seatbelt entries. Alternatively, move the hook below the isOnyxMigrated gate.

What I checked
  • When loading happens: In react-native-onyx 3.0.119, useOnyx reports loading only before init resolves, or when the key is uncached and an Onyx.merge for that exact key is still queued. Member-key merges and mergeCollection never queue under the collection root key. This confirms the PR's claim for the listed collection keys.
  • Default values: SESSION, ACCOUNT, MODAL, and RECENT_SEARCHES all have defaults in initialKeyStates (setup/index.ts:59).
  • Mount timing: FullstoryInitHandler, BulkActionStatusManager, ExportDownloadStatusManager, OnboardingModalNavigator, ProductTrainingContextProvider (the caller of useShouldSuppressPromotionalUI), and all the pages mount below the isOnyxMigrated gate. That gate opens only after init, because the migrations wait on Onyx.connect.
  • Search snapshot redirect: The App useOnyx wrapper sends policy_ and transactions_ to a snapshot_<hash> member key inside SearchScopeProvider. That member key can briefly be loading. WorkspaceSelector (filters) and useCarouselTransactionIDs (RHP) render outside that provider, so the redirect does not affect them.

@VickyStash

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

No issues remain. The PR looks good to merge from a code standpoint.

The one regression I flagged is fixed. "Undo risky key change" (3c8df96) restores the session-loading check in useSaveMarketingAttribution.ts. It also restores the file's entries in both seatbelt files. The hook now matches main exactly.

That commit is the only change since my last review. My findings for the other 21 source files still stand.

Optional: add a note to the PR description that useSaveMarketingAttribution was left out because it runs above the isOnyxMigrated gate. That would help the next cleanup batch avoid the same trap.


view run

@VickyStash
VickyStash marked this pull request as ready for review October 30, 2026 12:40
@VickyStash
VickyStash requested review from a team as code owners October 30, 2026 12:40
@melvin-bot
melvin-bot Bot requested review from nkdengineer and removed request for a team October 30, 2026 12:40
@melvin-bot

melvin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

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

@melvin-bot
melvin-bot Bot requested a review from trjExpensify October 30, 2026 12:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T12:57:42.540012Z 3c8df96 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.

@melvin-bot
melvin-bot Bot removed the request for review from a team October 30, 2026 12:40
@trjExpensify
trjExpensify removed their request for review October 30, 2026 14:07
@trjExpensify

Copy link
Copy Markdown
Contributor

PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself.

@mountiny

mountiny commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@VickyStash conflicts

…ded-keys

# Conflicts:
#	config/eslint/eslint.seatbelt.tsv
#	config/oxlint/oxlint.seatbelt.tsv
@VickyStash

Copy link
Copy Markdown
Contributor Author

Conflicts resolved! @nkdengineer please take a look

@nkdengineer

Copy link
Copy Markdown
Contributor

Will take a look today.

@nkdengineer

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 proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 that this PR follows the guidelines as stated in the Review Guidelines
  • 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 a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • 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-11-02.at.23.17.28.mov
Android: mWeb Chrome
Screen.Recording.2026-11-02.at.21.56.27.mov
iOS: HybridApp
Screen.Recording.2026-11-02.at.23.15.00.mov
iOS: mWeb Safari
Screen.Recording.2026-11-02.at.21.55.20.mov
MacOS: Chrome / Safari
Screen.Recording.2026-11-02.at.21.44.01.mov
Screen.Recording.2026-11-02.at.21.51.24.mov
Screen.Recording.2026-11-02.at.21.52.03.mov
Screen.Recording.2026-11-02.at.21.53.18.mov
Screen.Recording.2026-11-02.at.21.54.22.mov

@nkdengineer nkdengineer left a comment

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.

LGTM!

@melvin-bot
melvin-bot Bot requested a review from mountiny November 2, 2026 16:24
mountiny
mountiny previously approved these changes Nov 2, 2026

@mountiny mountiny left a comment

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.

Gotta merge main to resolve merge conflicts

…ded-keys

# Conflicts:
#	config/eslint/eslint.seatbelt.tsv
#	src/pages/Insights/InsightsDashboard.tsx
…ded-keys

# Conflicts:
#	config/oxlint/oxlint.seatbelt.tsv

@mountiny mountiny left a comment

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.

Looks good to me, thanks for pushing this ahead

@mountiny
mountiny merged commit 90cd9ab into Expensify:main Nov 3, 2026
36 of 37 checks passed
@OSBotify

OSBotify commented Nov 3, 2026

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

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify OSBotify mentioned this pull request Nov 3, 2026
99 tasks done
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.31-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR removes redundant internal loading checks without changing user workflows or making existing article instructions incorrect.

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.31-0 🚀

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

@OSBotify

OSBotify commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.5.31-4 🚀

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.

7 participants