@@ -442,34 +442,21 @@ export class SyncEngine implements RemoteSyncer {
442
442
onlineState : OnlineState ,
443
443
source : OnlineStateSource
444
444
) : void {
445
- // If we are the secondary client, we explicitly ignore the remote store's
446
- // online state (the local client may go offline, even though the primary
447
- // tab remains online) and only apply the primary tab's online state from
448
- // SharedClientState.
449
- if (
450
- ( this . isPrimaryClient && source === OnlineStateSource . RemoteStore ) ||
451
- ( ! this . isPrimaryClient && source === OnlineStateSource . SharedClientState )
452
- ) {
453
- this . assertSubscribed ( 'applyOnlineStateChange()' ) ;
454
- const newViewSnapshots = [ ] as ViewSnapshot [ ] ;
455
- this . queryViewsByQuery . forEach ( ( query , queryView ) => {
456
- const viewChange = queryView . view . applyOnlineStateChange ( onlineState ) ;
457
- debugAssert (
458
- viewChange . limboChanges . length === 0 ,
459
- 'OnlineState should not affect limbo documents.'
460
- ) ;
461
- if ( viewChange . snapshot ) {
462
- newViewSnapshots . push ( viewChange . snapshot ) ;
463
- }
464
- } ) ;
465
- this . syncEngineListener ! . onOnlineStateChange ( onlineState ) ;
466
- this . syncEngineListener ! . onWatchChange ( newViewSnapshots ) ;
467
-
468
- this . onlineState = onlineState ;
469
- if ( this . isPrimaryClient ) {
470
- this . sharedClientState . setOnlineState ( onlineState ) ;
445
+ this . assertSubscribed ( 'applyOnlineStateChange()' ) ;
446
+ const newViewSnapshots = [ ] as ViewSnapshot [ ] ;
447
+ this . queryViewsByQuery . forEach ( ( query , queryView ) => {
448
+ const viewChange = queryView . view . applyOnlineStateChange ( onlineState ) ;
449
+ debugAssert (
450
+ viewChange . limboChanges . length === 0 ,
451
+ 'OnlineState should not affect limbo documents.'
452
+ ) ;
453
+ if ( viewChange . snapshot ) {
454
+ newViewSnapshots . push ( viewChange . snapshot ) ;
471
455
}
472
- }
456
+ } ) ;
457
+ this . syncEngineListener ! . onOnlineStateChange ( onlineState ) ;
458
+ this . syncEngineListener ! . onWatchChange ( newViewSnapshots ) ;
459
+ this . onlineState = onlineState ;
473
460
}
474
461
475
462
async rejectListen ( targetId : TargetId , err : FirestoreError ) : Promise < void > {
@@ -968,6 +955,29 @@ export class MultiTabSyncEngine extends SyncEngine
968
955
return viewSnapshot ;
969
956
}
970
957
958
+ applyOnlineStateChange (
959
+ onlineState : OnlineState ,
960
+ source : OnlineStateSource
961
+ ) : void {
962
+ // If we are the primary client, the online state of all clients only
963
+ // depends on the online state of the local RemoteStore.
964
+ if ( this . isPrimaryClient && source === OnlineStateSource . RemoteStore ) {
965
+ super . applyOnlineStateChange ( onlineState , source ) ;
966
+ this . sharedClientState . setOnlineState ( onlineState ) ;
967
+ }
968
+
969
+ // If we are the secondary client, we explicitly ignore the remote store's
970
+ // online state (the local client may go offline, even though the primary
971
+ // tab remains online) and only apply the primary tab's online state from
972
+ // SharedClientState.
973
+ if (
974
+ ! this . isPrimaryClient &&
975
+ source === OnlineStateSource . SharedClientState
976
+ ) {
977
+ super . applyOnlineStateChange ( onlineState , source ) ;
978
+ }
979
+ }
980
+
971
981
async applyBatchState (
972
982
batchId : BatchId ,
973
983
batchState : MutationBatchState ,
0 commit comments