Repository navigation
Perf - lazy mount NavigateGlobalCreateProvider for faster scan camera - #94693
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09648354c6
ℹ️ 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".
| if (!isReady) { | ||
| return <NavigateGlobalCreateContext.Provider value={NO_OP}>{props.children}</NavigateGlobalCreateContext.Provider>; | ||
| } | ||
| return <NavigateGlobalCreateProviderInner {...props} />; |
There was a problem hiding this comment.
Keep the camera subtree mounted while enabling navigation
When isReady flips after the first effect, this branch changes the rendered root from NavigateGlobalCreateContext.Provider to NavigateGlobalCreateProviderInner, whose root is a different component type, so React unmounts and remounts props.children. In the scan flow that tears down and reinitializes ScanGlobalCreateInner/Camera immediately after the first paint, restarting the camera/media setup and causing the flicker or delay this change is trying to avoid; keep a stable provider subtree and only swap the context value/subscription component.
Useful? React with 👍 / 👎.
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@rinej is the PR ready for review? Thanks |
|
@brunovjk yup, it is |
Reviewer Checklist
Screenshots/VideosAndroid: HybridApp94693_android_native.movAndroid: mWeb Chrome94693_android_web.moviOS: HybridApp94693_android_native.moviOS: mWeb Safari94693_android_web.movMacOS: Chrome / SafariN/A |
brunovjk
left a comment
There was a problem hiding this comment.
NAB: I had one theoretical concern around fnRef.current starting as NO_OP before NavigateGlobalCreateSubscriber publishes the real callback. I tried to reproduce it by capturing/picking a receipt immediately after opening Scan, but couldn’t reproduce any lost navigation. What do you thunk @rinej? Thank you.
|
@brunovjk Good catch, in theory, there could be a small gap between the Camera's first paint and the subscriber's useEffect being committed.If that's the case, the gap is probably only around ~10ms, making it impossible to notice or to reproduce We could eliminate that gap by moving the ref write from useEffect into the subscriber's render body. However, I'm not sure that's the right trade-off, as we might lose some of the performance gains from this refactor |
|
|
||
| useEffect(() => { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect -- intentional one-tick defer to keep heavy Onyx subscriptions off the camera-mount critical path | ||
| setIsReady(true); |
There was a problem hiding this comment.
NAB: does it make sense to add a small render test here? The tricky part is the isReady flip + fnRef publish, and it could regress silently later. Something that checks the camera subtree stays mounted across the flip, and that navigateGlobalCreate still works once the subscriber is ready. Not blocking.
There was a problem hiding this comment.
sure, it makes sense, I added tests
| /** | ||
| * Owns the post-capture-only Onyx reads (default policy, self-DM report, | ||
| * billing grace periods) used by navigateGlobalCreate. Render-gated by a | ||
| * one-tick useEffect so the subscriptions don't block ManualEntryToScanReady. |
There was a problem hiding this comment.
Not a blocker, but we could probably drop ...(default policy, self-DM report, * billing grace periods) as it isn't a full list and could easily become outdated.
|
Thanks @Julesssss @cristipaval for the review, I added the small requested changes |
|
There are some failed checks for |
|
@rinej those checks should be passing in main now. Could you please pull main into this one? |
|
Its all green now, also updated changes after prettier -> fmt migration |
|
✋ 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! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/Julesssss in version: 9.4.29-0 🚀
|
|
🤖 Help site review: no changes required. I reviewed the changes in this PR against the help site articles under This is a pure internal performance refactor — it extracts the post-capture Onyx reads into a lazy-mounted
The existing scan/SmartScan help articles document the receipt-capture feature at a user level and don't describe camera mount timing or the internal navigation logic this PR touches, so none of them go stale as a result of this change. Since there are no user-observable changes, no draft help site PR was created. |
|
🚀 Deployed to staging by https://github.com/Julesssss in version: 9.4.31-0 🚀
|
|
🤖 Help site review: no changes required I reviewed the changes in this PR against Expensify's help site articles under Why: This is a purely internal performance refactor. It introduces a lazy-mounted Since nothing customer-facing changed, there's nothing in the help site to update, so I did not create a draft docs PR. @rinej, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR |
|
🚀 Deployed to production by https://github.com/grgia in version: 9.4.31-0 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Fixed Issues
$ #95708
PROPOSAL: #83502 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, 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.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.perfScanAndroid.mp4
Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari