@@ -128,10 +128,31 @@ export function initializeFirestore(
128
128
const provider = _getProvider ( app , 'firestore-exp' ) ;
129
129
130
130
if ( provider . isInitialized ( ) ) {
131
- throw new FirestoreError (
132
- Code . FAILED_PRECONDITION ,
133
- 'Firestore can only be initialized once per app.'
134
- ) ;
131
+ const existingInstance = provider . getImmediate ( ) ;
132
+ const initialOptions = provider . getOptions ( ) as FirestoreSettings ;
133
+ // Every option can currently be compared shallowly.
134
+ // We could currently do a deepEqual() on `settings` but if we add
135
+ // a new option to `FirestoreSettings` that needs a custom
136
+ // comparison, it should be coded separately. This makes it less
137
+ // likely to be missed.
138
+ const shallowOptionsKeys : Array < keyof FirestoreSettings > = [
139
+ 'cacheSizeBytes' ,
140
+ 'experimentalAutoDetectLongPolling' ,
141
+ 'experimentalForceLongPolling' ,
142
+ 'host' ,
143
+ 'ignoreUndefinedProperties' ,
144
+ 'ssl'
145
+ ] ;
146
+ if (
147
+ shallowOptionsKeys . every ( key => initialOptions [ key ] === settings [ key ] )
148
+ ) {
149
+ return existingInstance ;
150
+ } else {
151
+ throw new FirestoreError (
152
+ Code . FAILED_PRECONDITION ,
153
+ 'Firestore can only be initialized once per app.'
154
+ ) ;
155
+ }
135
156
}
136
157
137
158
if (
0 commit comments