diff --git a/.changeset/thick-rabbits-guess.md b/.changeset/thick-rabbits-guess.md new file mode 100644 index 00000000000..ce1c98bc893 --- /dev/null +++ b/.changeset/thick-rabbits-guess.md @@ -0,0 +1,8 @@ +--- +"firebase": patch +"@firebase/firestore": patch +--- + +[fixed] Removed a delay that may have prevented Firestore from immediately +reestablishing a network connection if a connectivity change occurred while +the app was in the background. diff --git a/packages/firestore/src/remote/remote_store.ts b/packages/firestore/src/remote/remote_store.ts index 599c71403bc..017fb552ecc 100644 --- a/packages/firestore/src/remote/remote_store.ts +++ b/packages/firestore/src/remote/remote_store.ts @@ -153,8 +153,11 @@ export class RemoteStore implements TargetMetadataProvider { connectivityMonitor: ConnectivityMonitor ) { this.connectivityMonitor = connectivityMonitor; - this.connectivityMonitor.addCallback((status: NetworkStatus) => { + this.connectivityMonitor.addCallback((_: NetworkStatus) => { asyncQueue.enqueueAndForget(async () => { + // Porting Note: Unlike iOS, `restartNetwork()` is called even when the + // network becomes unreachable as we don't have any other way to tear + // down our streams. if (this.canUseNetwork()) { logDebug( LOG_TAG, @@ -761,6 +764,8 @@ export class RemoteStore implements TargetMetadataProvider { this.offlineCauses.add(OfflineCause.ConnectivityChange); await this.disableNetworkInternal(); this.onlineStateTracker.set(OnlineState.Unknown); + this.writeStream.inhibitBackoff(); + this.watchStream.inhibitBackoff(); this.offlineCauses.delete(OfflineCause.ConnectivityChange); await this.enableNetworkInternal(); }