Skip to content

Commit

Permalink
Merge pull request #8105 from Expensify/marcaaron-disableRecheckOnDev
Browse files Browse the repository at this point in the history
[No QA] Disable recheck against local web API when local web API is in use
  • Loading branch information
luacmartins authored Mar 11, 2022
2 parents e404117 + 33223dc commit f916215
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/CONFIG.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default {
EXPENSIFY_CASH_REFERER: 'ecash',
},
IS_IN_PRODUCTION: Platform.OS === 'web' ? process.env.NODE_ENV === 'production' : !__DEV__,
IS_USING_LOCAL_WEB: useNgrok || expensifyURLRoot.includes('dev'),
PUSHER: {
APP_KEY: lodashGet(Config, 'PUSHER_APP_KEY', '268df511a204fbb60884'),
CLUSTER: 'mt1',
Expand Down
26 changes: 15 additions & 11 deletions src/libs/NetworkConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ function setOfflineStatus(isCurrentlyOffline) {
* `disconnected` event which takes about 10-15 seconds to emit.
*/
function subscribeToNetInfo() {
// Calling NetInfo.configure (re)checks current state. We use it to force a recheck whenever we (re)subscribe
NetInfo.configure({
// By default, NetInfo uses `/` for `reachabilityUrl`
// When App is served locally (or from Electron) this address is always reachable - even offline
// Using the API url ensures reachability is tested over internet
reachabilityUrl: `${CONFIG.EXPENSIFY.URL_API_ROOT}api`,
reachabilityTest: response => Promise.resolve(response.status === 200),

// If a check is taking longer than this time we're considered offline
reachabilityRequestTimeout: CONST.NETWORK.MAX_PENDING_TIME_MS,
});
// Note: We are disabling the configuration for NetInfo when using the local web API since requests can get stuck in a 'Pending' state and are not reliable indicators for "offline".
// If you need to test the "recheck" feature then switch to the production API proxy server.
if (!CONFIG.IS_USING_LOCAL_WEB) {
// Calling NetInfo.configure (re)checks current state. We use it to force a recheck whenever we (re)subscribe
NetInfo.configure({
// By default, NetInfo uses `/` for `reachabilityUrl`
// When App is served locally (or from Electron) this address is always reachable - even offline
// Using the API url ensures reachability is tested over internet
reachabilityUrl: `${CONFIG.EXPENSIFY.URL_API_ROOT}api`,
reachabilityTest: response => Promise.resolve(response.status === 200),

// If a check is taking longer than this time we're considered offline
reachabilityRequestTimeout: CONST.NETWORK.MAX_PENDING_TIME_MS,
});
}

// Subscribe to the state change event via NetInfo so we can update
// whether a user has internet connectivity or not.
Expand Down

0 comments on commit f916215

Please sign in to comment.