Skip to content
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

Incorporate hasPendingNetworkCheck #44565

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/libs/NetworkConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function subscribeToNetInfo(): () => void {
reachabilityUrl: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID || 'unknown'}`,
reachabilityMethod: 'GET',
reachabilityTest: (response) => {
hasPendingNetworkCheck = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this variable is used in recheckNetworkConnection... I think that's just a manual call to check for the connection, is that correct?
And if so, why would we need to update this variable both here and in the current place we are updating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah you're right. I'll fix that since any check including NetInfo.refresh() will now check for the state first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this.

I kept

if (hasPendingNetworkCheck) {
        return;
    }

so that we only see the [NetworkConnection] recheck NetInfo Log when necessary. Otherwise, we would see the log every 60s. But I can remove it if we want to add the Log to reachabilityShouldRun. The only problem with this is we won't be able to differentiate whether it came from the automatic or manual recheck.

if (!response.ok) {
return Promise.resolve(false);
}
Expand All @@ -123,6 +124,13 @@ function subscribeToNetInfo(): () => void {

// If a check is taking longer than this time we're considered offline
reachabilityRequestTimeout: CONST.NETWORK.MAX_PENDING_TIME_MS,
reachabilityShouldRun: () => {
if (hasPendingNetworkCheck) {
return false;
}
hasPendingNetworkCheck = true;
return true;
},
});
}

Expand Down Expand Up @@ -196,8 +204,7 @@ function recheckNetworkConnection() {
}

Log.info('[NetworkConnection] recheck NetInfo');
hasPendingNetworkCheck = true;
NetInfo.refresh().finally(() => (hasPendingNetworkCheck = false));
NetInfo.refresh();
}

export default {
Expand Down
Loading