Skip to content

Commit 8d08444

Browse files
Review
1 parent d87dc1e commit 8d08444

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,33 @@ export class IndexedDbPersistence implements Persistence {
580580
if (currentLeaseIsValid) {
581581
if (this.isLocalClient(currentPrimary) && this.networkEnabled) {
582582
return true;
583-
} else if (!this.isLocalClient(currentPrimary)) {
583+
}
584+
585+
if (!this.isLocalClient(currentPrimary)) {
586+
if (!currentPrimary!.allowTabSynchronization) {
587+
// Fail the `canActAsPrimary` check if the current leaseholder has
588+
// not opted into multi-tab synchronization. If this happens at
589+
// client startup, we reject the Promise returned by
590+
// `enablePersistence()` and the user can continue to use Firestore
591+
// with in-memory persistence.
592+
// If this fails during a lease refresh, we will instead block the
593+
// AsyncQueue from executing further operations. Note that this is
594+
// acceptable since mixing & matching different `synchronizeTabs`
595+
// settings is not supported.
596+
//
597+
// TODO(b/114226234): Remove this check when `synchronizeTabs` can
598+
// no longer be turned off.
599+
throw new FirestoreError(
600+
Code.FAILED_PRECONDITION,
601+
PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG
602+
);
603+
}
604+
584605
return false;
585606
}
586-
} else if (this.networkEnabled && this.inForeground) {
607+
}
608+
609+
if (this.networkEnabled && this.inForeground) {
587610
return true;
588611
}
589612

0 commit comments

Comments
 (0)