diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index df08cff23399..57a536a7faeb 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -70,7 +70,7 @@ function setOfflineStatus(isCurrentlyOffline: boolean, reason = ''): void { let shouldForceOffline = false; let isPoorConnectionSimulated: boolean | undefined; let connectionChanges: ConnectionChanges | undefined; - +let isNetworkStatusInitialized = false; // We do not depend on updates on the UI to determine the network status // or the offline status, so we can use `connectWithoutView` here. Onyx.connectWithoutView({ @@ -80,6 +80,8 @@ Onyx.connectWithoutView({ return; } + isNetworkStatusInitialized = true; + simulatePoorConnection(network); isPoorConnectionSimulated = !!network.shouldSimulatePoorConnection; @@ -231,6 +233,10 @@ function subscribeToNetInfo(): () => void { // Subscribe to the state change event via NetInfo so we can update // whether a user has internet connectivity or not. const unsubscribeNetInfo = NetInfo.addEventListener((state) => { + if (!isNetworkStatusInitialized) { + return; + } + Log.info('[NetworkConnection] NetInfo state change', false, {...state}); if (shouldForceOffline) { Log.info('[NetworkConnection] Not setting offline status because shouldForceOffline = true');