Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix the instance cache logic, closes #2666 #2667

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion sample/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 },
Expand Down
22 changes: 12 additions & 10 deletions src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -65,16 +65,18 @@ globalThis.ɵAngularfireInstanceCache ||= new Map();

export function ɵfetchInstance<T>(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();
Expand Down