perf: narrow Onyx subs in InvoiceSenderField and ReportField#90311
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba04c097ce
ℹ️ 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".
| const [canUpdateSenderWorkspace] = useOnyx(ONYXKEYS.COLLECTION.POLICY, { | ||
| selector: createCanUpdateSenderWorkspaceSelector(selectedParticipants, currentUserLogin, isFromGlobalCreate), | ||
| }); |
There was a problem hiding this comment.
Add dependencies for sender-workspace selector
When the policy collection is already cached and currentUserLogin, selectedParticipants, or isFromGlobalCreate changes afterward, this selector keeps the previously selected value because useOnyx only re-runs selector closures for external values when the dependency argument is provided. In the common initial-load path the selector can evaluate with currentUserLogin still undefined and leave canUpdateSenderWorkspace false, so eligible global invoice creators cannot open the “Send from” workspace picker until some unrelated policy update occurs.
Useful? React with 👍 / 👎.
| const policyID = selectedParticipants?.at(0)?.policyID; | ||
| const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS); | ||
| const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID); | ||
| const [outstandingReportsForPolicy] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID, {selector: createOutstandingReportsForPolicySelector(policyID)}); |
There was a problem hiding this comment.
Refresh selected outstanding reports when policy changes
This selector closes over policyID but the useOnyx call does not pass policyID as a dependency, so changing the participant/workspace while staying on the confirmation screen can leave outstandingReportsForPolicy selected for the previous policy. That makes the displayed/default report come from the wrong workspace until the derived outstanding-reports object changes for another reason; pass the policy ID in the dependency list so the selector is re-applied immediately.
Useful? React with 👍 / 👎.
|
PR doesn’t need product input as a performance PR. Unassigning and unsubscribing myself. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-05-16.at.1.26.42.AM.movAndroid: mWeb ChromeScreen.Recording.2026-05-15.at.11.45.03.PM.moviOS: HybridAppScreen.Recording.2026-05-15.at.11.32.56.PM.moviOS: mWeb SafariScreen.Recording.2026-05-15.at.11.38.07.PM.movMacOS: Chrome / SafariScreen.Recording.2026-05-15.at.11.39.43.PM.mov |
|
Can we also include the perf metric changes in the description? Would be helpful for future reference. |
|
@OlimpiaZurek |
This PR is part of a bigger refactor, so span metrics probably won’t show any statistically significant improvement on their own. What this PR actually improves is how often these components re-render. I added profiling results to the PR description. |
|
Can we get an adhoc build for Android? |
|
🚧 @cristipaval has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
| return name; | ||
| })(); | ||
|
|
||
| const outstandingReports = useOutstandingReports(undefined, isFromGlobalCreate && !isPerDiemRequest ? undefined : policyID, ownerAccountID, false); |
There was a problem hiding this comment.
Should we be using the scoped selector here as well?
There was a problem hiding this comment.
The hook has two paths. If selectedPolicyID exists, it only reads a single entry, so that part is scopeable. But for personal / self-DM / global create flows, it has to iterate through all policies, which means it still needs the full map.So to support both cases, we’d either need to add a second scoped subscription inside the same hook (which every caller would pay for, even if they don’t benefit from it), or split this into two separate hooks and migrate call sites accordingly. Both options feel like extra complexity for pretty limited gains here
There was a problem hiding this comment.
Thanks for the explanation
|
@Julesssss looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 @Julesssss 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! 🧪🧪
|
Don't recall, but not emergency. |
|
🚀 Deployed to staging by https://github.com/Julesssss in version: 9.3.78-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes are needed for this PR. This is a performance optimization that narrows Onyx subscriptions in |
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.78-1 🚀
|
Explanation of Change
Both
InvoiceSenderFieldandReportFieldsubscribed to Onyx collections without selectors, causing re-renders on every mutation across all policies/reports. This narrows them to per-key or selector-scoped subscriptions.PR 1 of 4. Follow-up: #90208 (structural decomposition of
MoneyRequestConfirmationListFooter). Subsequent PRs will narrow leaf Onyx subscriptions and add aConfirmationFieldsProvider.Results from profiling ( scenario: confirmation page open (policy-expense flow), then triggered an unrelated mutation (add/remove a tag in workspace):
Fixed Issues
$ #90385
Tests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))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.ScrollViewcomponent to make it scrollable when more elements are added to the page.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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari