Skip to content

Commit fa6fa29

Browse files
authored
Merge 9c35ff7 into d46d84b
2 parents d46d84b + 9c35ff7 commit fa6fa29

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/firestore/src/exp/database.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '@firebase/app-exp';
2525
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
2626
import { Provider } from '@firebase/component';
27+
import { deepEqual } from '@firebase/util';
2728

2829
import {
2930
IndexedDbOfflineComponentProvider,
@@ -128,10 +129,19 @@ export function initializeFirestore(
128129
const provider = _getProvider(app, 'firestore-exp');
129130

130131
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+
}
135145
}
136146

137147
if (

0 commit comments

Comments
 (0)