Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/build): add a maximum rendering timeout for SSG #27579

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions packages/angular/build/src/utils/server-rendering/render-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,46 @@ export async function renderPage({
},
];

let html: string | undefined;
assert(
bootstrapAppFnOrModule,
'The file "./main.server.mjs" does not have a default export for an AppServerModule or a bootstrapping function.',
);

let renderAppPromise: Promise<string>;
if (isBootstrapFn(bootstrapAppFnOrModule)) {
html = await renderApplication(bootstrapAppFnOrModule, {
renderAppPromise = renderApplication(bootstrapAppFnOrModule, {
document,
url: route,
platformProviders,
});
} else {
html = await renderModule(bootstrapAppFnOrModule, {
renderAppPromise = renderModule(bootstrapAppFnOrModule, {
document,
url: route,
extraProviders: platformProviders,
});
}

// The below should really handled by the framework!!!.
// See: https://github.com/angular/angular/issues/51549
let timer: NodeJS.Timeout;
const renderingTimeout = new Promise<never>(
(_, reject) =>
(timer = setTimeout(
() =>
reject(
new Error(
`Page ${new URL(route, 'resolve://').pathname} did not render in 30 seconds.`,
),
),
30_000,
)),
);

const html = await Promise.race([renderAppPromise, renderingTimeout]).finally(() =>
clearTimeout(timer),
);

if (inlineCriticalCss) {
const { InlineCriticalCssProcessor } = await import(
'../../utils/index-file/inline-critical-css'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async function render({ serverBundlePath, document, url }: RenderRequest): Promi
}

// The below should really handled by the framework!!!.
// See: https://github.com/angular/angular/issues/51549
let timer: NodeJS.Timeout;
const renderingTimeout = new Promise<never>(
(_, reject) =>
Expand Down