feat: Enable react-native-nitro-fetch (V3)#95518
Conversation
|
@mkhutornyi 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] |
|
|
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.
|
| const authenticateURL = `${getApiRoot()}api/${AUTHENTICATION_COMMAND}?`; | ||
|
|
||
| registerTokenRefresh({ | ||
| target: 'fetch', |
There was a problem hiding this comment.
❌ CONSISTENCY-2 (docs)
The NitroFetch target discriminator 'fetch' is hardcoded as a magic string. It appears here (target: 'fetch') and in clearTokenRefresh('fetch') on line 45 of this file, as well as in clearPrefetchOnAppStart/index.ts. Repeating this bare literal across call sites is easy to typo and hard to trace. Note this file already extracts CONTENT_TYPE_HEADER and the PR adds CONST.HTTP_HEADER_NAMES.AUTH_TOKEN, so this value should be a named constant too.
Extract a named constant and reuse it:
const NITRO_FETCH_TARGET = 'fetch';
// ...
clearTokenRefresh(NITRO_FETCH_TARGET);
// ...
registerTokenRefresh({
target: NITRO_FETCH_TARGET,
// ...
});Reviewed at: 75834b0 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75834b01df
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // When the user signs out, clear native startup prefetch state so the next cold start cannot replay | ||
| // a queued ReconnectApp request built with the previous session's auth token. | ||
| clearPrefetchOnAppStart(); |
There was a problem hiding this comment.
Clear startup prefetches on auth switches
Clearing native prefetch state only from signOut leaves stale state when the app changes identity without signing out, such as delegate connect/disconnect or HybridApp account switches that update SESSION/CREDENTIALS and then call openApp() (for example src/libs/actions/Delegate.ts:217-229 and :308-335). Because only ReconnectApp is queued under the stable ReconnectApp prefetch key, those openApp() transitions do not overwrite the old native queue/token-refresh config; if the user closes after switching accounts, the next cold start can replay and serve the previous account's prefetched ReconnectApp response to the new session. Please clear or re-register prefetch state whenever authToken/credentials change, not just on full sign-out.
Useful? React with 👍 / 👎.
| */ | ||
| import {fetch as nitroFetch, Headers as NitroHeaders, Request as NitroRequest, Response as NitroResponse} from 'react-native-nitro-fetch'; | ||
|
|
||
| globalThis.fetch = nitroFetch; |
There was a problem hiding this comment.
Keep Android pinning when replacing fetch
On Android release builds, routing every fetch through NitroFetch moves API traffic away from the React Native OkHttp client configured by CertificatePinning.install() (android/app/src/main/java/com/expensify/chat/CertificatePinning.kt:13-17 and :88-96). NitroFetch's Android transport is Cronet, so the existing OkHttp pinner/monitor and the HttpsURLConnection monitor do not observe these requests; making this global removes the current certificate-pinning coverage for all fetch-based API calls unless NitroFetch/Cronet is wired into the same validation path.
Useful? React with 👍 / 👎.
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
@MelvinBot provide summary of what's new from the previous PR. |
|
🤖 Summary: what's new in V3 vs the previous attempt ( TL;DR — there are no new App-side code changes. V3 is a straight re-application of the previously-merged-then-reverted PR
How I verified this
Where the regression fixes are: the 9 regressions listed in the description are not reflected in this PR's App diff (and the library version didn't bump), so the actual fixes live outside this App PR — in the linked native/hybrid change ( |
|
@chrispader won't this cause signout issue again? |
|
+1, I suggest we hold off this PR until we know the root cause of fireroom |
|
@mountiny could we please get an ad-hoc build for QA/C+ testing on this one? The auth issues should be fixed! |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
Asked for testing https://expensify.slack.com/archives/C09V78U42D8/p1783525894133159 |
They were fixed in which repo? |
In |
|
oh dammit, my commits weren't pushed, sorry... Will do that in a bit and then we would need to trigger another ad-hoc 🙌🏼 |
|
@mountiny please trigger another ad-hoc build, my bad 😵💫 |
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
|
🚧 mountiny 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! 🧪🧪
|
@roryabraham @mountiny @MonilBhavsar
Explanation of Change
This PR is a follow-up for two previously reverted PRs:
react-native-nitro-fetch(V2) #94469react-native-nitro-fetch#88110Replace native
fetchwithreact-native-nitro-fetch, then prefetches the startupOpenApp/ReconnectApprequest so it can begin before React Native JS is ready.NitroFetch is a native-backed Fetch API implementation built on Nitro Modules. By globally replacing fetch, Headers, Request, and Response on native, existing fetch(...) callsites and dependencies keep the same API while routing through NitroFetch. Web keeps the browser fetch implementation.
For startup,
prefetchOnAppStart(...)stores theOpenApp/ReconnectApprequest with a stableprefetchKey. On the next cold start, native code replays that request before the React Native runtime is loaded. When JS later sends the same request with the same prefetchKey, NitroFetch can serve the prefetched response from its native cache if it is ready, or fall back to the normal network request if it is not.Fixed and tested the following regressions:
Fixed Issues
$ #90023
PROPOSAL: https://expensify.slack.com/archives/C05LX9D6E07/p1778233186728969
MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/14000
Tests
Offline tests
None needed.
QA Steps
Run a full QA suite on all flows, since the changes in this PR affect all network requests across the whole app.
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