Repository navigation
fix: clear NO_RADIO when a request succeeds - #108128
adhorodyski wants to merge 12 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests that go offline now leave requests unanswered instead of answering them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/github.com/callstack-internal/Expensify-App into fix/network-state-clear-no-radio-on-success
The in-flight APITest request now fails when the radio drops instead of getting an answer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Krishna2323 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] |
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. |
Krishna2323
left a comment
There was a problem hiding this comment.
Small things: the comments at NetworkState.ts:36 and FailureTracker.ts:20 still refer only to INTERNET_UNREACHABLE. ReimbursementAccountPageOfflineTest.tsx:156 still says the fetch settles, but it's paused now.
| if (!hasRadio) { | ||
| Log.info('[NetworkState] NO_RADIO cleared — a successful request proved connectivity'); | ||
| hasRadio = true; | ||
| NetInfo.refresh(); |
There was a problem hiding this comment.
If NetInfo still reports isConnected=false when refresh() resolves, setHasRadio(false) sets NO_RADIO again. Each successful read then flips the app online and back offline, triggers a queue flush, and schedules a ReconnectApp, leaving the app offline.
A Jest test with an async refresh mock returning isConnected: false and 3 successful requests reproduces offline/online flips [false, true, false, true, false, true] and 3 reconnects.
Your issue comment says a success should count "no matter what the library says."
Is this PR intended to cover only the case where NetInfo corrects itself on refresh? The new test mocks refresh as a no-op, so it doesn't cover what happens after the re-read.
There was a problem hiding this comment.
That is on purpose. NetInfo gets the final say, so if it still says offline, we go back offline. It's correct though to re-ask for this state when any READ succeeds, and the library should be made solid with upstream fixes when proved unreliable (I did a patch in another PR with just that for Chrome). Added a test for it too.
There was a problem hiding this comment.
I can reproduce this on the iOS simulator. NetInfo is stuck on isConnected=false, type=none while every request returns 200, and the app gets into a loop.
A read succeeds and clears NO_RADIO. The app goes online and flushes the queue, causing pages to re-fire OpenHomePage, OpenSearchPage, and SearchForTodos. refresh() then sets NO_RADIO again, and the re-fired reads clear it again.
This repeats every ~560 ms, causing the banner to flicker nonstop. Every cycle also sends 3+ reads and a ReconnectApp.
Because going online is what triggers the next reads, giving NetInfo the final say doesn't leave the app offline,it keeps it looping.
Monosnap.screencast.2026-12-01.22-12-47.mp4
…lear-no-radio-on-success
Adds a test for a re-read that still reports no connection and updates comments that only mentioned INTERNET_UNREACHABLE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Krishna2323 I have reworded some explanations too so it's clear what I'm after with this PR. |
|
@adhorodyski I left a comment on this thread: #108128 (comment) Please check when you get a chance. Thanks! |
Clearing NO_RADIO straight from a successful request looped when NetInfo stayed wrong: going online re-fired reads, the re-read set NO_RADIO again, and those reads cleared it again. The success now only triggers the re-read. With that, the test workarounds that kept requests from succeeding while offline are no longer needed, so SessionTest, APITest and ReimbursementAccountPageOfflineTest go back to main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Krishna2323 really good catch, thank you. I worked on this for a while and settled on the fact that we shouldn't in fact force a true/false NO_RADIO by hand like initially proposed. I believe the current state of this PR is correct, we just use successful READs as clues to re-read the current network state and that allows for getting back online, which is not yet possible on current main. |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@Krishna2323 are you able to continue the review here? |
| // false does not re-set the hard stop. When the Ping finally passes, the NetInfo listener | ||
| // sees the app is already online and does nothing. | ||
| onRequestSuccess(() => { | ||
| if (!hasRadio) { |
There was a problem hiding this comment.
❌ CONSISTENCY-18 (docs)
On a successful request the INTERNET_UNREACHABLE path (below) clears the hard stop directly, but the new NO_RADIO path instead calls NetInfo.refresh() and then does nothing when hasRadio is still false. Why these two branches differ — that NetInfo can miss the radio reconnect so a re-read is needed, and that clearing hasRadio directly on success would flip the app briefly online, re-fire the reads that bypass the paused queue, and loop with each re-read — is non-obvious and only documented in the test, not at the code. The module comment above onRequestSuccess explains the overall wiring but not this asymmetry or the inner if (!hasRadio) return guard.
Add a short comment at the branch, e.g.:
if (!hasRadio) {
// NetInfo can miss a radio reconnect, so re-read it instead of clearing NO_RADIO here directly:
// clearing it on success would flip the app briefly online, re-fire the reads that bypass the
// paused queue, and loop. Only clear once the re-read actually finds a connection.
NetInfo.refresh().then(() => {
if (!hasRadio) {
return;
}
...
});
return;
}Reviewed at: f426eec | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Explanation of Change
A successful request can now also clear the
NO_RADIOhard stop after re-reading the current network state by NetInfo, so the app recovers even when it misses the reconnect.Fixed Issues
$ #107620
PROPOSAL: N/A
Tests
Unit tests:
tests/unit/NetworkStateReachabilityTest.ts, "success while NO_RADIO is set clears it once a NetInfo re-read finds a connection", which fails without the fix, and "success while NO_RADIO is set never brings the app online when the NetInfo re-read still reports no connection", which guards against the online/offline loop.Manual test, web (Chrome). The NetInfo patch from #108127 fixes the Wi-Fi case, so simulate the missed reconnect:
navigator.onLineat false, dispatchchangeonnavigator.connection, then restorenavigator.onLinewithout dispatching any event.OpenInitialSettingsPageread.ReconnectAppbeing sent and the offline banner goes away without a reload.Offline tests
QA Steps
Same as Offline tests, on staging.
// TODO: These must be filled out, or the issue title must include "[No QA]."
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
iOS: mWeb Safari
MacOS: Chrome / Safari
🤖 Generated with Claude Code