Skip to content

fix(core): try/catch the HMR/DI warning #2687

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

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nam
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
// Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
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.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
}
try {
if (JSON.stringify(options) !== JSON.stringify(app.options)) {
const hmr = !!(module as any).hot;
log('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
}
} catch (e) { }
return app;
}

Expand All @@ -66,17 +68,19 @@ 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) {
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;
try {
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.' : ''}`);
}
} catch (e) { }
return instance;
} else {
const newInstance = fn();
Expand Down