Skip to content

Commit 1530112

Browse files
authored
fix(core): try/catch the HMR/DI warning (#2687)
1 parent fce594b commit 1530112

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/core/firebase.app.module.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nam
4343
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
4444
// Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
4545
const app = (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp;
46-
if (JSON.stringify(options) !== JSON.stringify(app.options)) {
47-
const hmr = !!(module as any).hot;
48-
log('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
49-
}
46+
try {
47+
if (JSON.stringify(options) !== JSON.stringify(app.options)) {
48+
const hmr = !!(module as any).hot;
49+
log('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
50+
}
51+
} catch (e) { }
5052
return app;
5153
}
5254

@@ -66,17 +68,19 @@ globalThis.ɵAngularfireInstanceCache ||= new Map();
6668
export function ɵfetchInstance<T>(cacheKey: any, moduleName: string, app: FirebaseApp, fn: () => T, args: any[]): T {
6769
const [instance, ...cachedArgs] = globalThis.ɵAngularfireInstanceCache.get(cacheKey) || [];
6870
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;
71+
try {
72+
if (args.some((arg, i) => {
73+
const cachedArg = cachedArgs[i];
74+
if (arg && typeof arg === 'object') {
75+
return JSON.stringify(arg) !== JSON.stringify(cachedArg);
76+
} else {
77+
return arg !== cachedArg;
78+
}
79+
})) {
80+
const hmr = !!(module as any).hot;
81+
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.' : ''}`);
7582
}
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.' : ''}`);
79-
}
83+
} catch (e) { }
8084
return instance;
8185
} else {
8286
const newInstance = fn();

0 commit comments

Comments
 (0)