Skip to content

Commit 7f89643

Browse files
authored
fix(core): fix the instance cache logic (#2667)
1 parent 2ce41aa commit 7f89643

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

sample/src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020

2121
import { FirestoreComponent } from './firestore/firestore.component';
2222
import { AngularFireDatabaseModule, USE_EMULATOR as USE_DATABASE_EMULATOR } from '@angular/fire/database';
23-
import { AngularFirestoreModule, USE_EMULATOR as USE_FIRESTORE_EMULATOR } from '@angular/fire/firestore';
23+
import { AngularFirestoreModule, USE_EMULATOR as USE_FIRESTORE_EMULATOR, SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';
2424
import { AngularFireStorageModule } from '@angular/fire/storage';
2525
import { AngularFireAuthModule, USE_DEVICE_LANGUAGE, USE_EMULATOR as USE_AUTH_EMULATOR } from '@angular/fire/auth';
2626
import { AngularFireMessagingModule, SERVICE_WORKER, VAPID_KEY } from '@angular/fire/messaging';
@@ -73,6 +73,7 @@ import { FirestoreOfflineModule } from './firestore-offline/firestore-offline.mo
7373
UserTrackingService,
7474
ScreenTrackingService,
7575
PerformanceMonitoringService,
76+
{ provide: FIRESTORE_SETTINGS, useValue: { ignoreUndefinedProperties: true } },
7677
{ provide: ANALYTICS_DEBUG_MODE, useValue: true },
7778
{ provide: COLLECTION_ENABLED, useValue: true },
7879
{ provide: USE_AUTH_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9099] : undefined },

src/core/firebase.app.module.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nam
4545
const app = (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp;
4646
if (JSON.stringify(options) !== JSON.stringify(app.options)) {
4747
const hmr = !!(module as any).hot;
48-
log('error', `${app.toString()} already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
48+
log('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
4949
}
5050
return app;
5151
}
@@ -65,16 +65,18 @@ globalThis.ɵAngularfireInstanceCache ||= new Map();
6565

6666
export function ɵfetchInstance<T>(cacheKey: any, moduleName: string, app: FirebaseApp, fn: () => T, args: any[]): T {
6767
const [instance, ...cachedArgs] = globalThis.ɵAngularfireInstanceCache.get(cacheKey) || [];
68-
if (instance && args.some((arg, i) => {
69-
const cachedArg = cachedArgs[i];
70-
if (arg && typeof arg === 'object') {
71-
return JSON.stringify(arg) !== JSON.stringify(cachedArg);
72-
} else {
73-
return arg !== cachedArg;
68+
if (instance) {
69+
if (args.some((arg, i) => {
70+
const cachedArg = cachedArgs[i];
71+
if (arg && typeof arg === 'object') {
72+
return JSON.stringify(arg) !== JSON.stringify(cachedArg);
73+
} else {
74+
return arg !== cachedArg;
75+
}
76+
})) {
77+
const hmr = !!(module as any).hot;
78+
log('error', `${moduleName} was already initialized on the ${app.name} Firebase App instance with different settings.${hmr ? ' You may need to reload as Firebase is not HMR aware.' : ''}`);
7479
}
75-
})) {
76-
const hmr = !!(module as any).hot;
77-
log('error', `${moduleName} was already initialized on the ${app.name} Firebase App instance with different settings.${hmr ? ' You may need to reload as Firebase is not HMR aware.' : ''}`);
7880
return instance;
7981
} else {
8082
const newInstance = fn();

0 commit comments

Comments
 (0)