@@ -2,13 +2,14 @@ import { InjectionToken, NgZone, PLATFORM_ID, Injectable, Inject, Optional } fro
2
2
3
3
import { Observable , of , from } from 'rxjs' ;
4
4
import { catchError } from 'rxjs/operators' ;
5
- import { firestore } from 'firebase' ;
5
+ import { firestore } from 'firebase/app ' ;
6
6
7
7
import { Settings , CollectionReference , DocumentReference , QueryFn , AssociatedReference } from './interfaces' ;
8
8
import { AngularFirestoreDocument } from './document/document' ;
9
9
import { AngularFirestoreCollection } from './collection/collection' ;
10
10
11
11
import { FirebaseFirestore , FirebaseOptions , FirebaseAppConfig , FirebaseOptionsToken , FirebaseNameOrConfigToken , _firebaseAppFactory , FirebaseZoneScheduler } from 'angularfire2' ;
12
+ import { isPlatformBrowser } from '@angular/common' ;
12
13
13
14
/**
14
15
* The value of this token determines whether or not the firestore will have persistance enabled
@@ -119,13 +120,20 @@ export class AngularFirestore {
119
120
return firestore ;
120
121
} ) ;
121
122
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
+ }
129
137
}
130
138
131
139
/**
0 commit comments