@@ -2,13 +2,14 @@ import { InjectionToken, NgZone, PLATFORM_ID, Injectable, Inject, Optional } fro
22
33import { Observable , of , from } from 'rxjs' ;
44import { catchError } from 'rxjs/operators' ;
5- import { firestore } from 'firebase' ;
5+ import { firestore } from 'firebase/app ' ;
66
77import { Settings , CollectionReference , DocumentReference , QueryFn , AssociatedReference } from './interfaces' ;
88import { AngularFirestoreDocument } from './document/document' ;
99import { AngularFirestoreCollection } from './collection/collection' ;
1010
1111import { FirebaseFirestore , FirebaseOptions , FirebaseAppConfig , FirebaseOptionsToken , FirebaseNameOrConfigToken , _firebaseAppFactory , FirebaseZoneScheduler } from 'angularfire2' ;
12+ import { isPlatformBrowser } from '@angular/common' ;
1213
1314/**
1415 * The value of this token determines whether or not the firestore will have persistance enabled
@@ -119,13 +120,20 @@ export class AngularFirestore {
119120 return firestore ;
120121 } ) ;
121122
122- this . persistenceEnabled$ = zone . runOutsideAngular ( ( ) =>
123- shouldEnablePersistence ? from ( this . firestore . enablePersistence ( ) . then ( ( ) => true , ( ) => false ) )
124- : of ( false )
125- )
126- . pipe (
127- catchError ( ( ) => of ( false ) )
128- ) ; // https://github.com/firebase/firebase-js-sdk/issues/608
123+ if ( shouldEnablePersistence && isPlatformBrowser ( platformId ) ) {
124+ // We need to try/catch here because not all enablePersistence() failures are caught
125+ // https://github.com/firebase/firebase-js-sdk/issues/608
126+ const enablePersistence = ( ) => {
127+ try {
128+ return from ( this . firestore . enablePersistence ( ) . then ( ( ) => true , ( ) => false ) ) ;
129+ } catch ( e ) {
130+ return of ( false ) ;
131+ }
132+ } ;
133+ this . persistenceEnabled$ = zone . runOutsideAngular ( enablePersistence ) ;
134+ } else {
135+ this . persistenceEnabled$ = of ( false ) ;
136+ }
129137 }
130138
131139 /**
0 commit comments