|
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 } 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 |
@@ -32,22 +32,23 @@ export class FirebaseApp { |
32 | 32 | functions: (region?: string) => FirebaseFunctions; |
33 | 33 | } |
34 | 34 |
|
35 | | -export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string|FirebaseAppConfig|null) { |
| 35 | +export function _firebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string|FirebaseAppConfig|null) { |
36 | 36 | const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]'; |
37 | 37 | const config = typeof nameOrConfig === 'object' && nameOrConfig || {}; |
38 | 38 | config.name = config.name || name; |
39 | 39 | // Added any due to some inconsistency between @firebase/app and firebase types |
40 | 40 | const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0] as any; |
41 | 41 | // We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any |
42 | 42 | // Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206 |
43 | | - return (existingApp || firebase.initializeApp(options, config as any)) as FirebaseApp; |
| 43 | + return (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp; |
44 | 44 | } |
45 | 45 |
|
46 | 46 | const FirebaseAppProvider = { |
47 | 47 | provide: FirebaseApp, |
48 | 48 | useFactory: _firebaseAppFactory, |
49 | 49 | deps: [ |
50 | 50 | FirebaseOptionsToken, |
| 51 | + NgZone, |
51 | 52 | [new Optional(), FirebaseNameOrConfigToken] |
52 | 53 | ] |
53 | 54 | }; |
|
0 commit comments