Skip to content

Commit 845df28

Browse files
authored
Merge 1fce2a6 into 3871f26
2 parents 3871f26 + 1fce2a6 commit 845df28

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

packages/firestore/src/exp/database.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,31 @@ export function initializeFirestore(
128128
const provider = _getProvider(app, 'firestore-exp');
129129

130130
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+
}
135156
}
136157

137158
if (

0 commit comments

Comments
 (0)