Skip to content

fix(@angular/build): fail build and exclude routes when prerendering fails - #33971

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-prerender-failure-reporting
Aug 31, 2026
Merged

fix(@angular/build): fail build and exclude routes when prerendering fails#33971
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-prerender-failure-reporting

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

When a prerendered route fails to render (such as when a component throws during route activation), the render worker returned null content which was silently ignored. Consequently, no HTML file was written to disk, but the build still reported the route in prerender statistics, included it in prerendered-routes.json, and exited with code 0.

Now:

  • The render worker throws an error if content is null ('The content returned was empty.').
  • Prerendering records the error so the build fails with a non-zero exit code.
  • Prerendered routes recorded for manifest and statistics are derived strictly from routes that produced output files.

Closes #33965

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the prerendering process to ensure that only successfully prerendered routes are included in the final output. It updates prerenderPages to track and return successfully generated routes, refactors RenderResultItem into a discriminated union to distinguish between successful renders and errors, and adds an E2E test to verify this behavior. Feedback on the changes includes addressing a bug in the new E2E test where a try-catch block silently swallows assertion failures, and a recommendation to extract duplicated route-to-output-path resolution logic into a shared helper function.

Comment thread tests/e2e/tests/build/prerender/error-component-render.ts Outdated
Comment thread packages/angular/build/src/utils/server-rendering/prerender.ts
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Aug 31, 2026
@alan-agius4
alan-agius4 requested a review from clydin August 31, 2026 08:21
@alan-agius4
alan-agius4 force-pushed the fix-prerender-failure-reporting branch from 7ce0519 to c5021a0 Compare August 31, 2026 08:22
…fails

When a prerendered route failed to render (such as when a component throws
during route activation), the render worker returned null content which was
silently skipped. Consequently, no HTML file was written, but the build still
reported the route in prerender statistics, included it in prerendered-routes.json,
and exited with code 0.

Now:
- The render worker throws an error if content is null ('The content returned was empty.').
- Prerendering records the error so the build fails with a non-zero exit code.
- Prerendered routes recorded for manifest and statistics are derived strictly from routes that produced output files.

Closes angular#33965
@alan-agius4
alan-agius4 force-pushed the fix-prerender-failure-reporting branch from c5021a0 to 1dadd3d Compare August 31, 2026 08:23
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 31, 2026
@alan-agius4
alan-agius4 merged commit 5b850fd into angular:main Aug 31, 2026
66 of 68 checks passed
@alan-agius4
alan-agius4 deleted the fix-prerender-failure-reporting branch August 31, 2026 13:10
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prerendering reports routes it did not write, and the build succeeds

2 participants