Skip to content

Commit 4a085f1

Browse files
committed
Add --pessimistic option which allows you to continue the render process even if some routes fail to render
1 parent adfe2c6 commit 4a085f1

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ssr",
3-
"version": "0.10.30",
3+
"version": "0.10.31",
44
"description": "Angular server-side rendering implementation",
55
"main": "build/index.js",
66
"typings": "build/index.d.ts",

source/application/builder/impl/application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ApplicationImpl<V, M> implements Application<V> {
2727
) {}
2828

2929
prerender(options: PrerenderOptions = {pessimistic: false}): Observable<Snapshot<V>> {
30-
this.render.pessimistic = options.pessimistic || false;
30+
this.render.pessimistic = (options && options.pessimistic) || false;
3131

3232
return Observable.create(async (observe) => {
3333
if (this.render.routes == null || this.render.routes.length === 0) {

source/application/builder/prerenderer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import {OutputProducer} from '../../output';
2-
31
import {Application} from '../builder';
2+
import {OutputProducer} from '../../output';
3+
import {PrerenderOptions} from './options';
44

55
import {assertSnapshot} from '../../snapshot/assert';
66

77
export interface ApplicationPrerenderer {
8-
prerenderTo(output: OutputProducer): Promise<void>;
8+
prerenderTo(output: OutputProducer, options?: PrerenderOptions): Promise<void>;
99
}
1010

1111
export const applicationPrerenderer = <V>(application: Application<V>): ApplicationPrerenderer => {
1212
return {
13-
prerenderTo: async (output: OutputProducer): Promise<void> => {
13+
prerenderTo: async (output: OutputProducer, options?: PrerenderOptions): Promise<void> => {
1414
output.initialize();
1515

16-
const snapshots = application.prerender();
16+
const snapshots = application.prerender(options);
1717

1818
return new Promise<void>((resolve, reject) => {
1919
snapshots.subscribe(

source/bin/options/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface CommandLineOptions {
44
blacklist?: boolean;
55
debug: boolean;
66
output: OutputProducer;
7+
pessimistic: boolean; // ignore routes that cannot render
78
preboot: PrebootConfiguration | boolean;
89
project: Project;
910
templateDocument: string;

source/bin/options/parse.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const parseCommandLineOptions = (): CommandLineOptions => {
8080
return {
8181
debug,
8282
output,
83+
pessimistic,
8384
preboot,
8485
project,
8586
templateDocument: template.content(),
@@ -91,6 +92,9 @@ export const parseCommandLineOptions = (): CommandLineOptions => {
9192
// Enable preboot integration
9293
let enablePreboot: boolean = false;
9394

95+
// Ignore routes that fail to render (just emit warnings instead of failing the process)
96+
let pessimistic = false;
97+
9498
// Inline CSS resources in the compiled HTML output
9599
let inlineStylesheets: boolean = true;
96100

@@ -135,6 +139,7 @@ const parseCommandLine = () => {
135139
.option('-o, --output <path>', 'Output path to write rendered HTML documents to', 'dist')
136140
.option('-a, --application <applicationID>', 'Optional application ID if your CLI configuration contains multiple apps')
137141
.option('-P, --preboot [boolean | json-file | json-text]', 'Enable or disable preboot with optional configuration file or JSON text (otherwise automatically find the root element and use defaults)')
142+
.option('-R, --pessimistic [boolean]', 'Ignore routes that fail to render (just emit warnings, do not fail the whole run)')
138143
.option('-i, --inline [boolean]', 'Inline of resources referenced in links')
139144
.option('-S, --inline-svg [boolean]', 'Inline SVG <use xlink:href> instances (to resolve issues with absolute URI SVG identifiers eg http://localhost/#foo')
140145
.option('-I, --ipc', 'Send rendered documents to parent process through IPC instead of writing them to disk', false)
@@ -152,6 +157,9 @@ const parseCommandLine = () => {
152157
options.on('blacklist',
153158
value => blacklist = value == null ? true : value);
154159

160+
options.on('pessimistic',
161+
value => pessimistic = value == null ? true : value);
162+
155163
return options.parse(process.argv);
156164
};
157165

source/bin/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const applicationRenderer = applicationPrerenderer(application);
4141

4242
const execute = async () => {
4343
try {
44-
await applicationRenderer.prerenderTo(options.output);
44+
await applicationRenderer.prerenderTo(options.output, {pessimistic: options.pessimistic});
4545
}
4646
finally {
4747
// If we are debugging, then we are likely to produce a stack trace that includes compiled

source/output/svg.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const inlineVectorGraphics = (document: Document): void => {
2121

2222
const matchingDefinition = definitions.get(identifier.split(/[#\/]/g).pop());
2323
if (matchingDefinition == null) {
24-
throw new Error(`Cannot find matching SVG definition for ${identifier}`);
24+
console.warn(`Cannot find matching SVG definition for ${identifier}`);
25+
continue;
2526
}
2627

2728
link.parentElement.replaceChild(matchingDefinition.cloneNode(true), link);

0 commit comments

Comments
 (0)