@@ -24,6 +24,7 @@ import {
24
24
} from '@firebase/app-exp' ;
25
25
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types' ;
26
26
import { Provider } from '@firebase/component' ;
27
+ import { deepEqual } from '@firebase/util' ;
27
28
28
29
import {
29
30
IndexedDbOfflineComponentProvider ,
@@ -128,10 +129,19 @@ export function initializeFirestore(
128
129
const provider = _getProvider ( app , 'firestore-exp' ) ;
129
130
130
131
if ( provider . isInitialized ( ) ) {
131
- throw new FirestoreError (
132
- Code . FAILED_PRECONDITION ,
133
- 'Firestore can only be initialized once per app.'
134
- ) ;
132
+ const existingInstance = provider . getImmediate ( ) ;
133
+ const initialSettings = provider . getOptions ( ) as FirestoreSettings ;
134
+ if ( deepEqual ( initialSettings , settings ) ) {
135
+ return existingInstance ;
136
+ } else {
137
+ throw new FirestoreError (
138
+ Code . FAILED_PRECONDITION ,
139
+ 'initializeFirestore() has already been called with ' +
140
+ 'different options. To avoid this error, call initializeFirestore() with the ' +
141
+ 'same options as when it was originally called, or call getFirestore() to return the' +
142
+ ' already initialized instance.'
143
+ ) ;
144
+ }
135
145
}
136
146
137
147
if (
0 commit comments