Skip to content

Commit 6817bcc

Browse files
authored
fix(core): ensure the UMDs are importing things correctly for the lazy modules (#2676)
1 parent ae26b35 commit 6817bcc

17 files changed

+113
-50
lines changed

sample/angular.json

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -129,37 +129,7 @@
129129
"main": "server.ts",
130130
"tsConfig": "tsconfig.server.json",
131131
"bundleDependencies": true,
132-
"externalDependencies": [
133-
"firebase",
134-
"@firebase/analytics",
135-
"@firebase/analytics-types",
136-
"@firebase/app",
137-
"@firebase/app-types",
138-
"@firebase/auth",
139-
"@firebase/auth-interop-types",
140-
"@firebase/auth-types",
141-
"@firebase/component",
142-
"@firebase/database",
143-
"@firebase/database-types",
144-
"@firebase/firestore",
145-
"@firebase/firestore-types",
146-
"@firebase/functions",
147-
"@firebase/functions-types",
148-
"@firebase/installations",
149-
"@firebase/installations-types",
150-
"@firebase/logger",
151-
"@firebase/messaging",
152-
"@firebase/messaging-types",
153-
"@firebase/performance",
154-
"@firebase/performance-types",
155-
"@firebase/polyfill",
156-
"@firebase/remote-config",
157-
"@firebase/remote-config-types",
158-
"@firebase/storage",
159-
"@firebase/storage-types",
160-
"@firebase/util",
161-
"@firebase/webchannel-wrapper"
162-
]
132+
"externalDependencies": [ ]
163133
},
164134
"configurations": {
165135
"production": {

sample/firebase.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
"value": "public,max-age=31536000,immutable"
1616
}
1717
]
18+
}, {
19+
"source": "*-sw.js",
20+
"headers": [
21+
{
22+
"key": "Cache-Control",
23+
"value": "no-cache"
24+
}
25+
]
1826
}
1927
],
2028
"rewrites": [
@@ -26,7 +34,7 @@
2634
}
2735
],
2836
"functions": {
29-
"source": "functions"
37+
"source": "dist/sample"
3038
},
3139
"emulators": {
3240
"functions": {

sample/firestore-protos.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
path: './node_modules/@firebase/firestore/dist/src/protos',
3+
filter: /\.proto$/,
4+
pathTransform: (path: string) => {
5+
const name = path.split('./node_modules/@firebase/firestore/dist/')[1];
6+
return `file-loader?name=${name}!${path}`;
7+
}
8+
};

sample/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@types/jasminewd2": "~2.0.3",
5151
"codelyzer": "^6.0.0",
5252
"concurrently": "^5.3.0",
53+
"dir-loader": "^0.3.0",
5354
"express": "^4.17.1",
5455
"express-serve-static-core": "^0.1.1",
5556
"firebase-admin": "^8.13.0",

sample/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ngExpressEngine } from '@nguniversal/express-engine';
44
import * as express from 'express';
55
import { join } from 'path';
66

7-
import { AppServerModule } from './src/main.server';
7+
import { AppServerModule, } from './src/main.server';
88
import { APP_BASE_HREF } from '@angular/common';
99
import { existsSync } from 'fs';
1010

@@ -14,6 +14,9 @@ global['XMLHttpRequest'] = require('xhr2');
1414
global['WebSocket'] = require('ws');
1515
/* tslint:enable:no-string-literal */
1616

17+
// include the protos required to bundle firestore
18+
import 'dir-loader!./firestore-protos';
19+
1720
// The Express app is exported so that it can be used by serverless Functions.
1821
export function app() {
1922
const server = express();
@@ -22,7 +25,7 @@ export function app() {
2225

2326
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
2427
server.engine('html', ngExpressEngine({
25-
bootstrap: AppServerModule,
28+
bootstrap: AppServerModule
2629
}));
2730

2831
server.set('view engine', 'html');

sample/src/app/app-routing.module.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
33
import { HomeComponent } from './home/home.component';
44
import { ProtectedComponent } from './protected/protected.component';
5-
import { AngularFireAuthGuard } from '@angular/fire/auth-guard';
5+
import { AngularFireAuthGuard, canActivate, isNotAnonymous } from '@angular/fire/auth-guard';
66
import { SecondaryComponent } from './secondary/secondary.component';
77

88
const routes: Routes = [
9-
{ path: '', component: HomeComponent, outlet: 'primary' },
10-
{ path: '', component: SecondaryComponent, outlet: 'secondary' },
11-
{ path: '', component: SecondaryComponent, outlet: 'tertiary' },
9+
{ path: '', component: HomeComponent, outlet: 'primary', pathMatch: 'prefix' },
10+
{ path: '', component: SecondaryComponent, outlet: 'secondary', pathMatch: 'prefix' },
11+
{ path: '', component: SecondaryComponent, outlet: 'tertiary', pathMatch: 'prefix' },
1212
{ path: 'protected', component: ProtectedComponent, canActivate: [AngularFireAuthGuard] },
13+
{ path: 'lazy', loadChildren: () => import('./protected-lazy/protected-lazy.module').then(m => m.ProtectedLazyModule) },
1314
{ path: 'protected-lazy',
1415
loadChildren: () => import('./protected-lazy/protected-lazy.module').then(m => m.ProtectedLazyModule),
1516
canActivate: [AngularFireAuthGuard] },
1617
{ path: 'protected', component: ProtectedComponent, canActivate: [AngularFireAuthGuard], outlet: 'secondary' },
1718
{ path: 'protected', component: ProtectedComponent, canActivate: [AngularFireAuthGuard], outlet: 'tertiary' },
1819
{ path: 'protected-lazy',
1920
loadChildren: () => import('./protected-lazy/protected-lazy.module').then(m => m.ProtectedLazyModule),
20-
canActivate: [AngularFireAuthGuard],
21+
...canActivate(() => isNotAnonymous),
2122
outlet: 'secondary' },
2223
];
2324

sample/src/app/app.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ import { FirebaseApp } from '@angular/fire';
44
@Component({
55
selector: 'app-root',
66
template: `
7-
<a [routerLink]="[{ outlets: { primary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { primary: ['protected'] }}]">Protected</a> | <a [routerLink]="[{ outlets: { primary: ['protected-lazy'] }}]">Protected Lazy</a> | <a [routerLink]="[{ outlets: { primary: ['protected-lazy', 'asdf'] }}]">Protected Lazy Deep</a> | <a [routerLink]="[{ outlets: { primary: ['protected-lazy', '1', 'bob'] }}]">Protected Lazy Deep</a>
7+
<h1>AngularFire kitchen sink</h1>
8+
<h2>Primary outlet</h2>
9+
<nav>
10+
<a [routerLink]="[{ outlets: { primary: [] }}]">Home</a> |
11+
<a [routerLink]="[{ outlets: { primary: ['protected'] }}]">Protected</a> |
12+
<a [routerLink]="[{ outlets: { primary: ['lazy'] }}]">Lazy</a> |
13+
<a [routerLink]="[{ outlets: { primary: ['protected-lazy'] }}]">Protected Lazy</a> |
14+
<a [routerLink]="[{ outlets: { primary: ['protected-lazy', 'asdf'] }}]">Protected Lazy Deep</a> |
15+
<a [routerLink]="[{ outlets: { primary: ['protected-lazy', '1', 'bob'] }}]">Protected Lazy Deep</a></nav>
816
<router-outlet></router-outlet>
9-
<a [routerLink]="[{ outlets: { secondary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { secondary: ['protected'] }}]">Protected</a> | <a [routerLink]="[{ outlets: { secondary: ['protected-lazy'] }}]">Protected Lazy</a>
17+
<h2>Secondary outlet</h2>
18+
<nav><a [routerLink]="[{ outlets: { secondary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { secondary: ['protected'] }}]">Protected</a> | <a [routerLink]="[{ outlets: { secondary: ['protected-lazy'] }}]">Protected Lazy (no anonymous)</a></nav>
1019
<router-outlet name="secondary"></router-outlet>
11-
<a [routerLink]="[{ outlets: { tertiary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { tertiary: ['protected'] }}]">Protected</a>
20+
<h2>Yet anther outlet</h2>
21+
<nav><a [routerLink]="[{ outlets: { tertiary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { tertiary: ['protected'] }}]">Protected</a></nav>
1222
<router-outlet name="tertiary"></router-outlet>
1323
`,
1424
styles: [``]

sample/src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ import { UpboatsComponent } from './upboats/upboats.component';
8383
{ provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 8080] : undefined },
8484
{ provide: USE_FUNCTIONS_EMULATOR, useValue: environment.useEmulators ? ['localhost', 5001] : undefined },
8585
{ provide: NEW_ORIGIN_BEHAVIOR, useValue: true },
86-
{ provide: FUNCTIONS_ORIGIN, useFactory: () => isDevMode() ? undefined : location.origin },
86+
{ provide: FUNCTIONS_ORIGIN, useFactory: () => isDevMode() || typeof location === 'undefined' ? undefined : location.origin },
8787
{ provide: REMOTE_CONFIG_SETTINGS, useFactory: () => isDevMode() ? { minimumFetchIntervalMillis: 10_000 } : {} },
8888
{ provide: REMOTE_CONFIG_DEFAULTS, useValue: { background_color: 'red' } },
8989
{ provide: USE_DEVICE_LANGUAGE, useValue: true },

sample/src/app/app.server.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { NgModule } from '@angular/core';
1+
import { isDevMode, NgModule } from '@angular/core';
22
import { ServerModule, ServerTransferStateModule } from '@angular/platform-server';
33

44
import { AppModule } from './app.module';
55
import { AppComponent } from './app.component';
6+
import { APP_BASE_HREF } from '@angular/common';
67

78
@NgModule({
89
imports: [
910
AppModule,
1011
ServerModule,
1112
ServerTransferStateModule
1213
],
14+
providers: [
15+
{ provide: APP_BASE_HREF, useFactory: () => isDevMode() ? '/us-central1/ssr' : '/ssr' },
16+
],
1317
bootstrap: [AppComponent],
1418
})
1519
export class AppServerModule {}

sample/src/app/protected-lazy/protected-lazy.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p>protected-lazy works!</p>
1+
<p>lazy works!</p>
22

33
<ul>
44
<li *ngFor="let item of snapshot | async">

0 commit comments

Comments
 (0)