Skip to content

[POC] Remove dependencies argument from useOnyx - #93439

Closed
fabioh8010 wants to merge 34 commits into
Expensify:mainfrom
callstack-internal:feature/onyx-store-pr-3
Closed

[POC] Remove dependencies argument from useOnyx#93439
fabioh8010 wants to merge 34 commits into
Expensify:mainfrom
callstack-internal:feature/onyx-store-pr-3

Conversation

@fabioh8010

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline 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

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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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 a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

fabioh8010 and others added 8 commits June 15, 2026 17:10
Onyx store-based PR 3 removes the 3rd `dependencies` argument from `useOnyx`.
Migrate all 64 consumers:

- Selector-less calls drop the redundant 3rd argument.
- Inline selectors are extracted into `useCallback`-memoized selectors using the
  same dependency list (the established app idiom for useOnyx selectors).
- Factory-produced selectors use `useCallback((input) => factory(args)(input), [deps])`,
  extracting optional-chained dependencies into locals so React Compiler can
  preserve the memoization.

Typecheck, ESLint, and the React Compiler compliance check all pass.
…gine

`useParticipantsPolicies` / `useParticipantsPolicyTags` memoized their useOnyx
selector with the `participants` array as the dependency. When a caller passes a
fresh array with identical contents (e.g. `transaction?.participants ?? []` after
the transaction is cleared), the selector identity changes every render, which
defeats useOnyx's internal selector memoization and makes it re-subscribe on every
render — under the store-based `useSyncExternalStore` engine that never settles and
hangs (surfaced by the IOU confirmation UI tests during `afterEach` Onyx.clear()).

Key the memoized selector on the participants' policy IDs (the only data the
selector reads) instead of the array reference.
Audit follow-up to the participant-policy fix: harden the other migrated useOnyx
selectors whose memoization dependency is a non-primitive (array/Set) reference
that can be rebuilt every render, which defeats useOnyx's selector memoization and
never settles under the store-based engine.

- useArchivedReportsIDSet: memoize the returned Set at the source (helps every
  consumer, e.g. WorkspaceRoomsPage and OptionListContextProvider).
- useTransactionViolationOfWorkspace / PopoverReactionList: key the selector on the
  contents of the freshly-built Set / destructured account-ID array.
- useTransactionViolation / ReactionTooltipContent / InvoiceSenderField: key the
  selector on the contents of the Set param / prop array (callers pass fresh refs,
  e.g. `selectedParticipantsProp.filter(...)`).
# Conflicts:
#	src/components/ReportActionItem/MoneyRequestReceiptView.tsx
#	src/hooks/useTransactionViolationOfWorkspace.tsx
#	src/pages/Debug/Report/DebugReportPage.tsx
#	src/pages/inbox/report/ReportActionItemCreated.tsx
The content-key + eslint-disable selector-memoization pattern (e.g.
`useCallback(sel, [ids.join(',')])`) tripped React Compiler's
"missing/extra memoization dependencies" check, because the dep array
no longer matched the values the selector closure reads.

Replace it with source-stabilization: project each array/Set to the
primitive(s) or ID-array the selector actually consumes, stabilize that
reference with `useStableArrayReference` (set-state-during-render, no dep
array to mismatch), then key the selector memo on the stable value. Deps
now match the closure (compiler-happy) and stay reference-stable across
renders (no re-subscribe loop under the store-based engine).

- useParticipantsPolicies / useParticipantsPolicyTags: select on stable policyID array
- ReactionTooltipContent / PopoverReactionList: stable accountID array
- ExpenseReportListItem: stable transactionID array
- useTransactionViolation / useTransactionViolationOfWorkspace: stable sorted ID array, Set rebuilt in selector
- InvoiceSenderField: project to an isInvoiceRoom boolean (no array dep at all)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 56ba8d2)
@codecov

codecov Bot commented Jun 18, 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/components/ChronosTimerHeaderButton.tsx 86.36% <100.00%> (-0.60%) ⬇️
src/components/KYCWall/BaseKYCWall.tsx 28.97% <100.00%> (+1.65%) ⬆️
...stConfirmationList/sections/InvoiceSenderField.tsx 92.30% <100.00%> (+0.30%) ⬆️
...eyRequestConfirmationList/sections/ReportField.tsx 85.41% <100.00%> (+0.31%) ⬆️
...nents/Navigation/QuickCreationActionsBar/index.tsx 85.54% <100.00%> (ø)
...rc/components/Reactions/ReactionTooltipContent.tsx 95.00% <100.00%> (-0.46%) ⬇️
...nents/ReportActionItem/MoneyRequestReceiptView.tsx 69.23% <100.00%> (-0.25%) ⬇️
...eportPreview/MoneyRequestReportPreviewProvider.tsx 92.10% <100.00%> (ø)
...RequestReportPreview/ReportPreviewActionButton.tsx 90.38% <100.00%> (+0.38%) ⬆️
...earch/SearchList/ListItem/ReportListItemHeader.tsx 91.66% <100.00%> (ø)
... and 73 more
... and 56 files with indirect coverage changes

fabioh8010 and others added 7 commits June 22, 2026 08:47
PR 3 wrapped migrated useOnyx selectors in useCallback to keep them
reference-stable after the dependencies arg was removed. React Compiler
already memoizes selectors (inline or named) keyed on their closed-over
values, so the useCallback wrappers are redundant in compiled files —
the project convention is to let the compiler handle memoization.

- Inline the selector directly into useOnyx({selector: ...}) for files
  React Compiler compiles; the compiler memoizes the inline arrow + the
  options object exactly as useCallback would.
- Keep useCallback only for the 4 files that bail out of the compiler
  (BaseKYCWall, SuggestionMention, usePaginatedReportActions,
  usePaymentOptions) — there the compiler can't memoize, and the
  no-inline-useOnyx-selector lint rule enforces it.
- useTransactionsByID keeps a named selector (inlining collided a param
  name with an outer variable); it still compiles and memoizes.
- Input stabilization (useStableArrayReference / primitive projection)
  is unchanged — it remains the load-bearing piece the compiler keys on.

Verified: typecheck clean, eslint no hard errors, react-compiler
per-file scan (only the 2 known bailouts), affected jest suites green
with no re-subscribe hangs on the store-based engine.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 58935de)
…e-pr-3

# Conflicts:
#	src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx
#	src/pages/inbox/report/ReportActionItemCreated.tsx
#	src/pages/workspace/WorkspacesListPage.tsx
Selector-input stabilization is only load-bearing under the store-based
(eager) engine in PR 5; on PR 3's engine it's at most a redundant recompute.
Revert the 7 sites to plain inline selectors closing over their original
input so PR 3 stays a focused "remove the dependencies argument" change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e-pr-3

# Conflicts:
#	package-lock.json
#	package.json
#	src/components/MoneyRequestConfirmationList/sections/ReportField.tsx
#	src/components/ReportActionItem/MoneyRequestView.tsx
#	src/hooks/useArchivedReportsIDSet.ts
#	src/pages/workspace/rooms/WorkspaceRoomsPage.tsx
@fabioh8010

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa1b539d25

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread package-lock.json
"resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-3.0.85.tgz",
"integrity": "sha512-F4rhP9IHDoXejZjMhq4HTl6+p8xih5TdrEVRaaA9SSW1dGwF08c1mUQjnDmZ1Pq81OIVWhbkYnfVhYNKwgSaIA==",
"version": "3.0.86",
"resolved": "git+ssh://git@github.com/Expensify/react-native-onyx.git#5739db80220ed6bd205ae6d5114657eed727307e",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the Onyx git dependency on HTTPS

This lockfile entry now resolves react-native-onyx through git+ssh://git@github.com/... even though package.json pins the same SHA via git+https://.... The setup action runs npm ci on cache misses (.github/actions/composite/setupNode/action.yml), and npm uses the lockfile's resolved git URL, so fresh CI runners or developer machines without GitHub SSH credentials will fail to install this dependency. Please regenerate or edit the lockfile so the resolved URL stays on HTTPS.

Useful? React with 👍 / 👎.

@fabioh8010

Copy link
Copy Markdown
Contributor Author

Closing in favor of #97594

@fabioh8010 fabioh8010 closed this Jul 31, 2026
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.

1 participant