-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: selfDMReportID getting undefined, when user tries track manual expense first time with own email #76315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…xpense first time with own email
|
@abdulrahuman5196 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] |
|
|
||
| const selfDMReportID = useMemo(() => findSelfDMReportID(), []); | ||
| const [selfDMReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`, {canBeMissing: true}); | ||
| const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ PERF-4 (docs)
Subscribing to the entire ONYXKEYS.COLLECTION.REPORT collection causes this component to re-render whenever ANY report in Onyx changes. This can be thousands of reports, leading to significant performance degradation. The reports object is also passed to the trackExpense callback, causing the callback to be recreated on every report change.
Suggested fix: Instead of subscribing to all reports, consider:
- Using a selector to only subscribe to the self DM report:
useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (reports) => findSelfDMReportID() ? reports[\${ONYXKEYS.COLLECTION.REPORT}${findSelfDMReportID()}`] : undefined})` - Or ensuring the self DM report is created before this component mounts
- Or using a derived key that only updates when the self DM report changes
| // More information can be found here: https://github.com/Expensify/App/issues/73728 | ||
| Navigation.setNavigationActionToMicrotaskQueue(() => { | ||
| Navigation.navigate(iouConfirmationPageRoute); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ PERF-4 (docs)
The reports dependency in this callback causes trackExpense to be recreated whenever ANY report changes in Onyx. This is extremely expensive as it can trigger re-renders in any component that uses this callback.
Suggested fix: Instead of depending on the entire reports collection, memoize only the specific self DM report data you need:
const selfDMReportData = useMemo(() => {
const selfDMReportID = findSelfDMReportID();
return selfDMReportID ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`] : undefined;
}, [reports]);Then use selfDMReportData in the callback dependencies instead of reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdulrahuman5196 github-actions is suggesting similar to the first approach of my proposal. should i go with this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Burhan-Rashid Could you fix the https://github.com/Expensify/App/pull/76315/files#r2572802828 comment? I think once that is fixed this might go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed that. Using selector now to get the selfDMReport.
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Explanation of Change
Fixed Issues
$#75721
PROPOSAL:#75721 (comment)
Tests
Offline tests
same as 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 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.native.mp4
Android: mWeb Chrome
android.web.mp4
iOS: Native
ios.native.mp4
iOS: mWeb Safari
ios.web.mp4
MacOS: Chrome / Safari
mac.os.web.mp4