|
1 |
| -import { InjectionToken, NgModule, Optional } from '@angular/core'; |
| 1 | +import { InjectionToken, NgModule, Optional, NgZone } from '@angular/core'; |
2 | 2 | import { auth, database, firestore, functions, messaging, storage, analytics, remoteConfig } from 'firebase/app';
|
3 | 3 | // @ts-ignore (https://github.com/firebase/firebase-js-sdk/pull/1206)
|
4 | 4 | import firebase from 'firebase/app'; // once fixed can pull in as "default as firebase" above
|
@@ -39,22 +39,23 @@ export class FirebaseApp {
|
39 | 39 | remoteConfig: () => FirebaseRemoteConfig;
|
40 | 40 | }
|
41 | 41 |
|
42 |
| -export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string|FirebaseAppConfig|null) { |
| 42 | +export function _firebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string|FirebaseAppConfig|null) { |
43 | 43 | const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
|
44 | 44 | const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
|
45 | 45 | config.name = config.name || name;
|
46 | 46 | // Added any due to some inconsistency between @firebase/app and firebase types
|
47 | 47 | const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0] as any;
|
48 | 48 | // We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
|
49 | 49 | // Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
|
50 |
| - return (existingApp || firebase.initializeApp(options, config as any)) as FirebaseApp; |
| 50 | + return (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp; |
51 | 51 | }
|
52 | 52 |
|
53 | 53 | const FirebaseAppProvider = {
|
54 | 54 | provide: FirebaseApp,
|
55 | 55 | useFactory: _firebaseAppFactory,
|
56 | 56 | deps: [
|
57 | 57 | FIREBASE_OPTIONS,
|
| 58 | + NgZone, |
58 | 59 | [new Optional(), FIREBASE_APP_NAME]
|
59 | 60 | ]
|
60 | 61 | };
|
|
0 commit comments