@@ -197,6 +197,7 @@ export class IndexedDbPersistence implements Persistence {
197
197
queue : AsyncQueue ;
198
198
serializer : JsonProtoSerializer ;
199
199
sequenceNumberSyncer : SequenceNumberSyncer ;
200
+ force : boolean ;
200
201
} ) : Promise < IndexedDbPersistence > {
201
202
if ( ! IndexedDbPersistence . isAvailable ( ) ) {
202
203
throw new FirestoreError (
@@ -213,14 +214,15 @@ export class IndexedDbPersistence implements Persistence {
213
214
options . lruParams ,
214
215
options . queue ,
215
216
options . serializer ,
216
- options . sequenceNumberSyncer
217
+ options . sequenceNumberSyncer ,
218
+ options . force
217
219
) ;
218
220
await persistence . start ( ) ;
219
221
return persistence ;
220
222
}
221
223
222
224
private readonly document : Document | null ;
223
- private readonly window : Window ;
225
+ private readonly window : Window | null ;
224
226
225
227
// Technically these types should be `| undefined` because they are
226
228
// initialized asynchronously by start(), but that would be more misleading
@@ -254,7 +256,7 @@ export class IndexedDbPersistence implements Persistence {
254
256
private readonly queryCache : IndexedDbQueryCache ;
255
257
private readonly indexManager : IndexedDbIndexManager ;
256
258
private readonly remoteDocumentCache : IndexedDbRemoteDocumentCache ;
257
- private readonly webStorage : Storage ;
259
+ private readonly webStorage : Storage | null ;
258
260
readonly referenceDelegate : IndexedDbLruDelegate ;
259
261
260
262
private constructor (
@@ -265,7 +267,8 @@ export class IndexedDbPersistence implements Persistence {
265
267
lruParams : LruParams ,
266
268
private readonly queue : AsyncQueue ,
267
269
serializer : JsonProtoSerializer ,
268
- private readonly sequenceNumberSyncer : SequenceNumberSyncer
270
+ private readonly sequenceNumberSyncer : SequenceNumberSyncer ,
271
+ private readonly takeoverPrimary : boolean
269
272
) {
270
273
this . referenceDelegate = new IndexedDbLruDelegate ( this , lruParams ) ;
271
274
this . dbName = persistenceKey + IndexedDbPersistence . MAIN_DATABASE ;
@@ -285,9 +288,11 @@ export class IndexedDbPersistence implements Persistence {
285
288
this . window = platform . window ;
286
289
this . webStorage = this . window . localStorage ;
287
290
} else {
288
- throw new FirestoreError (
289
- Code . UNIMPLEMENTED ,
290
- 'IndexedDB persistence is only available on platforms that support LocalStorage.'
291
+ this . window = platform . window ;
292
+ this . webStorage = null ;
293
+ log . error (
294
+ LOG_TAG ,
295
+ 'LocalStorage is unavailable. Multi-tab functionality may not be supported.'
291
296
) ;
292
297
}
293
298
}
@@ -299,7 +304,6 @@ export class IndexedDbPersistence implements Persistence {
299
304
*/
300
305
private start ( ) : Promise < void > {
301
306
assert ( ! this . started , 'IndexedDbPersistence double-started!' ) ;
302
- assert ( this . window !== null , "Expected 'window' to be defined" ) ;
303
307
304
308
return SimpleDb . openOrCreate (
305
309
this . dbName ,
@@ -526,9 +530,11 @@ export class IndexedDbPersistence implements Persistence {
526
530
// the client atomically, but we can't. So we opt to delete the IndexedDb
527
531
// entries first to avoid potentially reviving a zombied client.
528
532
inactiveClients . forEach ( inactiveClient => {
529
- this . window . localStorage . removeItem (
530
- this . zombiedClientLocalStorageKey ( inactiveClient . clientId )
531
- ) ;
533
+ if ( this . webStorage ) {
534
+ this . webStorage . removeItem (
535
+ this . zombiedClientLocalStorageKey ( inactiveClient . clientId )
536
+ ) ;
537
+ }
532
538
} ) ;
533
539
}
534
540
}
@@ -551,6 +557,10 @@ export class IndexedDbPersistence implements Persistence {
551
557
552
558
/** Checks whether `client` is the local client. */
553
559
private isLocalClient ( client : DbPrimaryClient | null ) : boolean {
560
+ console . error ( 'this id' , this . clientId ) ;
561
+ if ( client ) {
562
+ console . error ( 'client id' , client . ownerId ) ;
563
+ }
554
564
return client ? client . ownerId === this . clientId : false ;
555
565
}
556
566
@@ -590,6 +600,11 @@ export class IndexedDbPersistence implements Persistence {
590
600
}
591
601
592
602
if ( ! this . isLocalClient ( currentPrimary ) ) {
603
+ if ( this . takeoverPrimary ) {
604
+ console . error ( 'WHOOOOO LETS TAKE IT' ) ;
605
+ return true ;
606
+ }
607
+ console . error ( 'gg no primary for you' ) ;
593
608
if ( ! currentPrimary ! . allowTabSynchronization ) {
594
609
// Fail the `canActAsPrimary` check if the current leaseholder has
595
610
// not opted into multi-tab synchronization. If this happens at
@@ -974,6 +989,9 @@ export class IndexedDbPersistence implements Persistence {
974
989
* handler.
975
990
*/
976
991
private attachWindowUnloadHook ( ) : void {
992
+ if ( ! this . window ) {
993
+ return ;
994
+ }
977
995
if ( typeof this . window . addEventListener === 'function' ) {
978
996
this . windowUnloadHandler = ( ) => {
979
997
// Note: In theory, this should be scheduled on the AsyncQueue since it
@@ -992,6 +1010,9 @@ export class IndexedDbPersistence implements Persistence {
992
1010
}
993
1011
994
1012
private detachWindowUnloadHook ( ) : void {
1013
+ if ( ! this . window ) {
1014
+ return ;
1015
+ }
995
1016
if ( this . windowUnloadHandler ) {
996
1017
assert (
997
1018
typeof this . window . removeEventListener === 'function' ,
@@ -1008,6 +1029,9 @@ export class IndexedDbPersistence implements Persistence {
1008
1029
* cleanup logic in `shutdown()`.
1009
1030
*/
1010
1031
private isClientZombied ( clientId : ClientId ) : boolean {
1032
+ if ( ! this . webStorage ) {
1033
+ return false ;
1034
+ }
1011
1035
try {
1012
1036
const isZombied =
1013
1037
this . webStorage . getItem ( this . zombiedClientLocalStorageKey ( clientId ) ) !==
@@ -1031,6 +1055,9 @@ export class IndexedDbPersistence implements Persistence {
1031
1055
* clients are ignored during primary tab selection.
1032
1056
*/
1033
1057
private markClientZombied ( ) : void {
1058
+ if ( ! this . webStorage ) {
1059
+ return ;
1060
+ }
1034
1061
try {
1035
1062
this . webStorage . setItem (
1036
1063
this . zombiedClientLocalStorageKey ( this . clientId ) ,
@@ -1044,6 +1071,9 @@ export class IndexedDbPersistence implements Persistence {
1044
1071
1045
1072
/** Removes the zombied client entry if it exists. */
1046
1073
private removeClientZombiedEntry ( ) : void {
1074
+ if ( ! this . webStorage ) {
1075
+ return ;
1076
+ }
1047
1077
try {
1048
1078
this . webStorage . removeItem (
1049
1079
this . zombiedClientLocalStorageKey ( this . clientId )
0 commit comments