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

+2-1
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

+2-2
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

+1-1
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

+4-3
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

src/storage/storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class AngularFireStorage {
2929
) {
3030
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
3131
this.storage = zone.runOutsideAngular(() => {
32-
const app = _firebaseAppFactory(options, nameOrConfig);
32+
const app = _firebaseAppFactory(options, zone, nameOrConfig);
3333
return app.storage(storageBucket || undefined);
3434
});
3535
}

test/ng-build/build.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cd ./test/ng-build/ng6 && yarn && npx ng build --prod &&
2-
cd ../ng7 && yarn && npx ng build --prod &&
3-
cd ../ng8 && yarn && npx ng build --prod
1+
cd ./test/ng-build/ng6 && yarn && yarn build:prod &&
2+
cd ../ng7 && yarn && yarn build:prod &&
3+
cd ../ng8 && yarn && yarn build:prod

test/ng-build/ng6/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@angular/platform-browser": "6.0.1",
2424
"@angular/platform-browser-dynamic": "6.0.1",
2525
"@angular/router": "6.0.1",
26+
"firebase": "<7",
2627
"core-js": "^2.4.1",
2728
"rxjs": "^6.0.0",
2829
"zone.js": "^0.8.14"

test/ng-build/ng6/src/app/app.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AngularFirestore } from '@angular/fire/firestore';
66
import { AngularFireStorage } from '@angular/fire/storage';
77
import { AngularFireMessaging } from '@angular/fire/messaging';
88
import { AngularFireFunctions } from '@angular/fire/functions';
9+
import { AngularFirePerformance } from '@angular/fire/performance';
910

1011
@Component({
1112
selector: 'app-root',
@@ -38,8 +39,9 @@ export class AppComponent {
3839
private readonly afStore: AngularFirestore,
3940
private readonly storage: AngularFireStorage,
4041
private readonly messaging: AngularFireMessaging,
41-
private readonly functions: AngularFireFunctions
42+
private readonly functions: AngularFireFunctions,
43+
private readonly perf: AngularFirePerformance
4244
) {
43-
console.log(app, db, auth, afStore, storage, messaging, functions);
45+
console.log(app, db, auth, afStore, storage, messaging, functions, perf);
4446
}
4547
}

test/ng-build/ng6/src/app/app.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AngularFirestoreModule } from '@angular/fire/firestore';
77
import { AngularFireStorageModule } from '@angular/fire/storage';
88
import { AngularFireFunctionsModule } from '@angular/fire/functions';
99
import { AngularFireMessagingModule } from '@angular/fire/messaging';
10+
import { AngularFirePerformanceModule } from '@angular/fire/performance';
1011

1112
import { AppComponent } from './app.component';
1213

@@ -29,7 +30,8 @@ import { AppComponent } from './app.component';
2930
AngularFirestoreModule,
3031
AngularFireStorageModule,
3132
AngularFireMessagingModule,
32-
AngularFireFunctionsModule
33+
AngularFireFunctionsModule,
34+
AngularFirePerformanceModule
3335
],
3436
bootstrap: [AppComponent]
3537
})

test/ng-build/ng7/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"ng": "ng",
66
"start": "ng serve",
77
"build": "ng build",
8+
"build:prod": "ng build --prod",
89
"test": "ng test",
910
"lint": "ng lint",
1011
"e2e": "ng e2e"

test/ng-build/ng7/src/app/app.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AngularFirestore } from '@angular/fire/firestore';
77
import { AngularFireStorage } from '@angular/fire/storage';
88
import { AngularFireMessaging } from '@angular/fire/messaging';
99
import { AngularFireFunctions } from '@angular/fire/functions';
10+
import { AngularFirePerformance } from '@angular/fire/performance';
1011

1112
@Component({
1213
selector: 'app-root',
@@ -22,8 +23,9 @@ export class AppComponent {
2223
private readonly afStore: AngularFirestore,
2324
private readonly storage: AngularFireStorage,
2425
private readonly messaging: AngularFireMessaging,
25-
private readonly functions: AngularFireFunctions
26+
private readonly functions: AngularFireFunctions,
27+
private readonly perf: AngularFirePerformance
2628
) {
27-
console.log(app, db, auth, afStore, storage, messaging, functions);
29+
console.log(app, db, auth, afStore, storage, messaging, functions, perf);
2830
}
2931
}

test/ng-build/ng7/src/app/app.module.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { AngularFirestoreModule } from '@angular/fire/firestore';
88
import { AngularFireStorageModule } from '@angular/fire/storage';
99
import { AngularFireMessagingModule } from '@angular/fire/messaging';
1010
import { AngularFireFunctionsModule } from '@angular/fire/functions';
11+
import { AngularFirePerformanceModule } from '@angular/fire/performance';
12+
import { AngularFireAuthGuardModule } from '@angular/fire/auth-guard';
1113

1214
import { AppComponent } from './app.component';
1315

@@ -30,7 +32,9 @@ import { AppComponent } from './app.component';
3032
AngularFirestoreModule,
3133
AngularFireStorageModule,
3234
AngularFireMessagingModule,
33-
AngularFireFunctionsModule
35+
AngularFireFunctionsModule,
36+
AngularFirePerformanceModule,
37+
AngularFireAuthGuardModule
3438
],
3539
providers: [],
3640
bootstrap: [AppComponent]

0 commit comments

Comments
 (0)