Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT in src/libs/ReportUtils.ts (part 7)#93562
Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT in src/libs/ReportUtils.ts (part 7)#93562truph01 wants to merge 6 commits into
Conversation
|
@DylanDylann 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] |
| } = route; | ||
| const {accountID} = useCurrentUserPersonalDetails(); | ||
| const [selfDMReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${findSelfDMReportID()}`); | ||
| const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); |
There was a problem hiding this comment.
❌ PERF-11 (docs)
useOnyx(ONYXKEYS.COLLECTION.REPORT) without a selector subscribes to the entire reports collection. The component will re-render whenever any report in the collection changes, even though allReports is only consumed inside the onSelectWorkspace callback. This is especially costly because the reports collection can be very large.
Other files in this same PR correctly use a selector to narrow down to a single report (e.g., selector: (reports) => getPolicyExpenseChat(accountID, policyID, reports ?? {})). Since policy?.id here comes from the callback parameter and is not known at render time, consider one of these approaches:
- Use
useOnyxwith a selector that returns a map keyed by policyID of only policy expense chats, reducing the data size. - Use
Onyx.getValue(ONYXKEYS.COLLECTION.REPORT)(a non-reactive read) inside the callback if a one-shot lookup is sufficient, avoiding the subscription entirely. - If the subscription must remain, add a selector that extracts only the minimal data needed.
Reviewed at: e1cc8fb | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Fixed by creating selector
|
|
||
| const {accountID} = useCurrentUserPersonalDetails(); | ||
| const isTransactionDraft = shouldUseTransactionDraft(action); | ||
| const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); |
There was a problem hiding this comment.
❌ PERF-11 (docs)
useOnyx(ONYXKEYS.COLLECTION.REPORT) without a selector subscribes to the entire reports collection. The component will re-render whenever any report in the collection changes, even though allReports is only consumed inside the onSelectWorkspace callback. This is especially costly because the reports collection can be very large.
Other files in this same PR correctly use a selector to narrow down to a single report (e.g., selector: (reports) => getPolicyExpenseChat(accountID, policyID, reports ?? {})). Since policy?.id here comes from the callback parameter and is not known at render time, consider one of these approaches:
- Use
useOnyxwith a selector that returns a map keyed by policyID of only policy expense chats, reducing the data size. - Use
Onyx.getValue(ONYXKEYS.COLLECTION.REPORT)(a non-reactive read) inside the callback if a one-shot lookup is sufficient, avoiding the subscription entirely. - If the subscription must remain, add a selector that extracts only the minimal data needed.
Reviewed at: e1cc8fb | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Fixed by creating selector
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.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fbc277b67a
ℹ️ 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 {accountID} = useCurrentUserPersonalDetails(); | ||
| const isTransactionDraft = shouldUseTransactionDraft(action); | ||
| const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); |
There was a problem hiding this comment.
Avoid subscribing to all reports in the time picker
On high-traffic accounts, opening this workspace picker now subscribes the screen to the entire report collection even though the reports are only needed after a row is selected. That means unrelated report updates can push a huge allReports object through this component and re-render the picker, whereas the previous click-time lookup did not make this screen a live subscriber. Please derive the needed policy-expense chat(s) with a selector instead of consuming the raw collection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed by creating selector
| } = route; | ||
| const {accountID} = useCurrentUserPersonalDetails(); | ||
| const [selfDMReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${findSelfDMReportID()}`); | ||
| const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); |
There was a problem hiding this comment.
Avoid subscribing to all reports in the per diem picker
On high-traffic accounts, opening this workspace picker now subscribes the screen to the entire report collection even though the reports are only needed after a row is selected. That means unrelated report updates can push a huge allReports object through this component and re-render the picker, whereas the previous click-time lookup did not make this screen a live subscriber. Please derive the needed policy-expense chat(s) with a selector instead of consuming the raw collection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed by creating selector
Explanation of Change
This PR focus on refactoring the places where getPolicyExpenseChat are called directly in component and hook (We already do a few in Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT in src/libs/ReportUtils.ts (part 6) #93423)
Fixed Issues
$ #66416
PROPOSAL:
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand 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
Screen.Recording.2026-06-15.at.15.26.45.mov