Skip to content

Commit 60fd575

Browse files
authored
fix(core): support Firebase 7 peer and fix zone instabilities (#2240)
* Allowing Firebase 7 as a peer * Fixed the zone.js issue in the injectable `FirebaseApp`, this also fixes the zone instability caused by loading `AngularFirePerformanceModule` * Added tests for Angular 9 RC (haven't included them in the Travis job yet)
1 parent 97d8532 commit 60fd575

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1146
-10185
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ angularfire2-*.tgz
1313
.DS_Store
1414
yarn-error.log
1515
*.bak
16-
package-lock.json
16+
package-lock.json
17+
test/ng-build/**/yarn.lock

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular/fire",
3-
"version": "5.2.1",
3+
"version": "5.2.2",
44
"description": "The official library of Firebase and Angular.",
55
"private": true,
66
"scripts": {
@@ -42,7 +42,7 @@
4242
"@angular/platform-browser": ">=6.0.0 <9 || ^9.0.0-0",
4343
"@angular/platform-browser-dynamic": ">=6.0.0 <9 || ^9.0.0-0",
4444
"@angular/router": ">=6.0.0 <9 || ^9.0.0-0",
45-
"firebase": ">= 5.5.7 <7",
45+
"firebase": ">= 5.5.7 <8",
4646
"firebase-tools": "^6.10.0",
4747
"fuzzy": "^0.1.3",
4848
"inquirer": "^6.2.2",

src/auth/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class AngularFireAuth {
4444
) {
4545
const scheduler = new FirebaseZoneScheduler(zone, platformId);
4646
this.auth = zone.runOutsideAngular(() => {
47-
const app = _firebaseAppFactory(options, nameOrConfig);
47+
const app = _firebaseAppFactory(options, zone, nameOrConfig);
4848
return app.auth();
4949
});
5050

src/core/firebase.app.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InjectionToken, NgModule, Optional } from '@angular/core';
1+
import { InjectionToken, NgModule, Optional, NgZone } from '@angular/core';
22
import { auth, database, firestore, functions, messaging, storage } from 'firebase/app';
33
// @ts-ignore (https://github.com/firebase/firebase-js-sdk/pull/1206)
44
import firebase from 'firebase/app'; // once fixed can pull in as "default as firebase" above
@@ -32,22 +32,23 @@ export class FirebaseApp {
3232
functions: (region?: string) => FirebaseFunctions;
3333
}
3434

35-
export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string|FirebaseAppConfig|null) {
35+
export function _firebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string|FirebaseAppConfig|null) {
3636
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
3737
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
3838
config.name = config.name || name;
3939
// Added any due to some inconsistency between @firebase/app and firebase types
4040
const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0] as any;
4141
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
4242
// 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;
4444
}
4545

4646
const FirebaseAppProvider = {
4747
provide: FirebaseApp,
4848
useFactory: _firebaseAppFactory,
4949
deps: [
5050
FirebaseOptionsToken,
51+
NgZone,
5152
[new Optional(), FirebaseNameOrConfigToken]
5253
]
5354
};

src/database-deprecated/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class AngularFireDatabase {
2222
zone: NgZone
2323
) {
2424
this.database = zone.runOutsideAngular(() => {
25-
const app = _firebaseAppFactory(options, nameOrConfig);
25+
const app = _firebaseAppFactory(options, zone, nameOrConfig);
2626
return app.database(databaseURL || undefined);
2727
});
2828
}

src/database/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class AngularFireDatabase {
2020
) {
2121
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
2222
this.database = zone.runOutsideAngular(() => {
23-
const app = _firebaseAppFactory(options, nameOrConfig);
23+
const app = _firebaseAppFactory(options, zone, nameOrConfig);
2424
return app.database(databaseURL || undefined);
2525
});
2626
}

src/firestore/firestore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class AngularFirestore {
125125
) {
126126
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
127127
this.firestore = zone.runOutsideAngular(() => {
128-
const app = _firebaseAppFactory(options, nameOrConfig);
128+
const app = _firebaseAppFactory(options, zone, nameOrConfig);
129129
const firestore = app.firestore();
130130
firestore.settings(settings || DefaultFirestoreSettings);
131131
return firestore;

src/functions/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class AngularFireFunctions {
3030
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
3131

3232
this.functions = zone.runOutsideAngular(() => {
33-
const app = _firebaseAppFactory(options, nameOrConfig);
33+
const app = _firebaseAppFactory(options, zone, nameOrConfig);
3434
return app.functions(region || undefined);
3535
});
3636

src/messaging/messaging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AngularFireMessaging {
2727
const requireMessaging = from(import('firebase/messaging'));
2828

2929
this.messaging = requireMessaging.pipe(
30-
map(() => _firebaseAppFactory(options, nameOrConfig)),
30+
map(() => _firebaseAppFactory(options, zone, nameOrConfig)),
3131
map(app => app.messaging()),
3232
runOutsideAngular(zone)
3333
);

src/performance/performance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class AngularFirePerformance {
3131
) {
3232

3333
// @ts-ignore zapping in the UMD in the build script
34-
const requirePerformance = from(import('firebase/performance'));
34+
const requirePerformance = from(zone.runOutsideAngular(() => import('firebase/performance')));
3535

3636
this.performance = requirePerformance.pipe(
3737
// SEMVER while < 6 need to type, drop next major

0 commit comments

Comments
 (0)