From 8cd0dbe84320b2f8b1a7efaa93567975bb975a23 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Wed, 18 Nov 2020 18:33:50 -0500 Subject: [PATCH] fix(core): fix the instance cache logic --- sample/src/app/app.module.ts | 3 ++- src/core/firebase.app.module.ts | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sample/src/app/app.module.ts b/sample/src/app/app.module.ts index 4610f5b2a..7dceb39d5 100644 --- a/sample/src/app/app.module.ts +++ b/sample/src/app/app.module.ts @@ -20,7 +20,7 @@ import { import { FirestoreComponent } from './firestore/firestore.component'; import { AngularFireDatabaseModule, USE_EMULATOR as USE_DATABASE_EMULATOR } from '@angular/fire/database'; -import { AngularFirestoreModule, USE_EMULATOR as USE_FIRESTORE_EMULATOR } from '@angular/fire/firestore'; +import { AngularFirestoreModule, USE_EMULATOR as USE_FIRESTORE_EMULATOR, SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore'; import { AngularFireStorageModule } from '@angular/fire/storage'; import { AngularFireAuthModule, USE_DEVICE_LANGUAGE, USE_EMULATOR as USE_AUTH_EMULATOR } from '@angular/fire/auth'; import { AngularFireMessagingModule, SERVICE_WORKER, VAPID_KEY } from '@angular/fire/messaging'; @@ -73,6 +73,7 @@ import { FirestoreOfflineModule } from './firestore-offline/firestore-offline.mo UserTrackingService, ScreenTrackingService, PerformanceMonitoringService, + { provide: FIRESTORE_SETTINGS, useValue: { ignoreUndefinedProperties: true } }, { provide: ANALYTICS_DEBUG_MODE, useValue: true }, { provide: COLLECTION_ENABLED, useValue: true }, { provide: USE_AUTH_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9099] : undefined }, diff --git a/src/core/firebase.app.module.ts b/src/core/firebase.app.module.ts index e1942e7e0..a28b52057 100644 --- a/src/core/firebase.app.module.ts +++ b/src/core/firebase.app.module.ts @@ -45,7 +45,7 @@ export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nam const app = (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp; if (JSON.stringify(options) !== JSON.stringify(app.options)) { const hmr = !!(module as any).hot; - log('error', `${app.toString()} already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`); + log('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`); } return app; } @@ -65,16 +65,18 @@ globalThis.ɵAngularfireInstanceCache ||= new Map(); export function ɵfetchInstance(cacheKey: any, moduleName: string, app: FirebaseApp, fn: () => T, args: any[]): T { const [instance, ...cachedArgs] = globalThis.ɵAngularfireInstanceCache.get(cacheKey) || []; - if (instance && args.some((arg, i) => { - const cachedArg = cachedArgs[i]; - if (arg && typeof arg === 'object') { - return JSON.stringify(arg) !== JSON.stringify(cachedArg); - } else { - return arg !== cachedArg; + if (instance) { + if (args.some((arg, i) => { + const cachedArg = cachedArgs[i]; + if (arg && typeof arg === 'object') { + return JSON.stringify(arg) !== JSON.stringify(cachedArg); + } else { + return arg !== cachedArg; + } + })) { + const hmr = !!(module as any).hot; + 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.' : ''}`); } - })) { - const hmr = !!(module as any).hot; - 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.' : ''}`); return instance; } else { const newInstance = fn();