Repository navigation
perf: stop Getting started and the Spend empty state re-rendering when Create expense opens - #106712
Conversation
|
@nyomanjyotisa 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] |
|
This PR adds a new |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@MelvinBot test |
|
PR doesn’t need product input as a performance refactor PR. Unassigning and unsubscribing myself. |
| await act(async () => { | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}draft1`, {transactionID: 'draft1'}); | ||
| }); | ||
| const createExpenseItem = result.current.items.find((item) => item.key === 'createExpense'); |
There was a problem hiding this comment.
Could we grab createExpenseItem before adding the draft? Otherwise, the old subscription refreshes result.current, so this test passes without the fix too.
There was a problem hiding this comment.
thanks, it now grabs the item before writing the draft, so it fails without the fix
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid-pr106712-after-v3.mp4Android: mWeb ChromeAndroid-Chrome-pr106712-clean.mp4iOS: HybridAppiOS-pr106712-after.mp4iOS: mWeb SafariiOS-Safari-pr106712-after-v3.mp4MacOS: Chrome / SafarimacOS-Chrome-pr106712-after.mp4 |
| onPress: () => startMoneyRequest(CONST.IOU.TYPE.CREATE, generateReportID(), draftTransactionIDs, CONST.IOU.REQUEST_TYPE.SCAN), | ||
| onPress: () => { | ||
| // Read the drafts on press, since a subscription would re-render Home when Create expense writes its draft. | ||
| Onyx.get(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT).then((drafts) => |
There was a problem hiding this comment.
Done, switched to await.
| interceptAnonymousUser(() => { | ||
| startMoneyRequest(iouType, generateReportID(), draftTransactionIDs); | ||
| // Read the drafts on press, since a subscription would re-render this hidden tab when Create expense writes its draft. | ||
| Onyx.get(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT).then((drafts) => startMoneyRequest(iouType, generateReportID(), validTransactionDraftIDsSelector(drafts))); |
There was a problem hiding this comment.
Done, switched to await.
| const startMoneyRequestSpy = jest.spyOn(MoneyRequest, 'startMoneyRequest').mockImplementation(() => {}); | ||
| await act(async () => { | ||
| await Onyx.merge(ONYXKEYS.SESSION, SESSION); | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}draft1`, {transactionID: 'draft1'}); |
There was a problem hiding this comment.
This test writes the draft before render, so it also passes on main. There, the subscription already holds ['draft1'] when the component first renders.
Writing the draft after render would not fix it here. On main, the draft write re-renders the component, so the button gets a new handler with ['draft1'] before the press. This differs from the hook test, where the captured item kept its old closure.
To test the actual goal, you could count renders while Search is hidden. Can you look into updating this please?
There was a problem hiding this comment.
Good point, added a render-count test that writes a draft while Search is hidden and expects no re-render. It fails on main.
| onPress: () => startMoneyRequest(CONST.IOU.TYPE.CREATE, generateReportID(), draftTransactionIDs, CONST.IOU.REQUEST_TYPE.SCAN), | ||
| onPress: () => { | ||
| // Read the drafts on press, since a subscription would re-render Home when Create expense writes its draft. | ||
| Onyx.get(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT).then((drafts) => |
| interceptAnonymousUser(() => { | ||
| startMoneyRequest(iouType, generateReportID(), draftTransactionIDs); | ||
| // Read the drafts on press, since a subscription would re-render this hidden tab when Create expense writes its draft. | ||
| Onyx.get(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT).then((drafts) => startMoneyRequest(iouType, generateReportID(), validTransactionDraftIDsSelector(drafts))); |
There was a problem hiding this comment.
Done, switched to await.
|
This PR adds a new |
|
This PR adds a new |
|
resolved conflicts |
mountiny
left a comment
There was a problem hiding this comment.
Thanks, lets move this ahead
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.43-0 🚀
|
|
No help site update needed — this PR only optimizes rendering performance without changing user workflows, UI labels, beta availability, or making existing article instructions incorrect. |
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.47-0 🚀
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.51-0 🚀
|
|
🚀 Deployed to production by https://github.com/marcaaron in version: 9.5.51-1 🚀
Bundle Size Analysis (Sentry): |



Explanation of Change
Starting Create expense writes a transaction draft. Two screens that stay mounted while it opens subscribed to the list of draft IDs, so they re-rendered in the same commit that mounts the Create expense page:
useGettingStartedItems). Home is the screen under the RHP, so it is still mounted.EmptySearchView). Hidden native tabs are not frozen since the native tab bar.Both only use the IDs inside a press handler, to clear old drafts in
startMoneyRequest. They now read the drafts withOnyx.getwhen the button is pressed instead of subscribing, so a draft write no longer re-renders them.EmptySearchViewalso passes the screen focus fromSearchtouseSearchTypeMenuSections, the same gate #105620 added for the narrow Spend menu, so its Submit button stops watching drafts while Spend is hidden.On these two buttons the span now starts after
Onyx.getresolves, which is a cache read. The Create menu path is unchanged.Performance, iOS simulator (iPhone 18 Pro, DEV build), new account,
ManualOpenCreateExpenseopened from Home through the actions menu, 9 interleaved blocks of 6 opens after warmup:In the commit that mounts the page,
GettingStartedSection(about 9ms) andEmptySearchView(about 6ms) no longer render. Accounts that already have expenses do not show these two sections, so they will see little change.Fixed Issues
$ #105517
PROPOSAL:
Tests
Offline tests
Same as tests while offline. Opening Create expense makes no API call, so it works the same.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)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.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
Getting started and Spend empty state Create expense buttons: VIDEO_TO_UPLOAD
iOS: mWeb Safari
MacOS: Chrome / Safari