Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
With prerendering/SSR (v22), when a component throws or logs an error during the render, the error is written to the console but the render still completes: the build exits 0 and ships the degraded page. There is no way to make the swallowed error fail the render or the build.
Reproduction
In a prerendered component, run a browser-only API during render without a platform guard, for example header.getBoundingClientRect() in a method that runs during prerender, or document.querySelectorAll(...). Build with prerendering.
Actual
The prerender logs ERROR TypeError: ...getBoundingClientRect is not a function (or ERROR ReferenceError: document is not defined), ng build exits 0, and the affected content is silently missing from the prerendered HTML. The broken page ships.
Expected
A way to fail the build when the prerender render logs or throws such an error.
Mechanism (current pipeline, v22)
The component error is routed to the default ErrorHandler during ApplicationRef.tick (it console.errors, it does not rethrow). @angular/ssr awaits ApplicationRef.whenStable(), which resolves even after the error, and serializes the degraded DOM. handle() returns a response, no error reaches the builder, the build succeeds.
Related
angular/angular#33642 tracks the same concept on the legacy renderModuleFactory API (open, P2). This report is the current @angular/build and @angular/ssr pipeline.
angular/universal#1371 (closed as a duplicate of angular/angular#33642) is the prerender-specific framing.
angular/angular#47039 (closed) is the silent-empty variant.
Angular version: 22.x
Proposed solution
Expose rethrowApplicationErrors (or an equivalent) for server/prerender rendering. @angular/core already has this as a long-standing TestBed option: setting it makes errors thrown during ApplicationRef.tick rethrow instead of being swallowed. TestBed implements it by overriding the internal application-error-handler so a tick error is rethrown rather than passed to ErrorHandler.handleError. The prerender/SSR path routes errors through that same handler where they are currently swallowed, so the same interception could fail the render on any swallowed change-detection error, with zero application changes. Open to whatever mechanism the team prefers (a provideServerRendering option, a build flag), this is one concrete low-cost path.
Alternatives considered
A CLI-side fix (a fail-on-render-error flag on the @angular/build prerender builder) would also stop the broken page from shipping, but the error is swallowed one layer earlier, in @angular/core's ErrorHandler during ApplicationRef.tick, so raising it there is the more central fix and also covers plain SSR, not only the prerender builder. That is why this is filed here and not on angular-cli.
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
With prerendering/SSR (v22), when a component throws or logs an error during the render, the error is written to the console but the render still completes: the build exits 0 and ships the degraded page. There is no way to make the swallowed error fail the render or the build.
Reproduction
In a prerendered component, run a browser-only API during render without a platform guard, for example header.getBoundingClientRect() in a method that runs during prerender, or document.querySelectorAll(...). Build with prerendering.
Actual
The prerender logs ERROR TypeError: ...getBoundingClientRect is not a function (or ERROR ReferenceError: document is not defined), ng build exits 0, and the affected content is silently missing from the prerendered HTML. The broken page ships.
Expected
A way to fail the build when the prerender render logs or throws such an error.
Mechanism (current pipeline, v22)
The component error is routed to the default ErrorHandler during ApplicationRef.tick (it console.errors, it does not rethrow). @angular/ssr awaits ApplicationRef.whenStable(), which resolves even after the error, and serializes the degraded DOM. handle() returns a response, no error reaches the builder, the build succeeds.
Related
angular/angular#33642 tracks the same concept on the legacy renderModuleFactory API (open, P2). This report is the current @angular/build and @angular/ssr pipeline.
angular/universal#1371 (closed as a duplicate of angular/angular#33642) is the prerender-specific framing.
angular/angular#47039 (closed) is the silent-empty variant.
Angular version: 22.x
Proposed solution
Expose rethrowApplicationErrors (or an equivalent) for server/prerender rendering. @angular/core already has this as a long-standing TestBed option: setting it makes errors thrown during ApplicationRef.tick rethrow instead of being swallowed. TestBed implements it by overriding the internal application-error-handler so a tick error is rethrown rather than passed to ErrorHandler.handleError. The prerender/SSR path routes errors through that same handler where they are currently swallowed, so the same interception could fail the render on any swallowed change-detection error, with zero application changes. Open to whatever mechanism the team prefers (a provideServerRendering option, a build flag), this is one concrete low-cost path.
Alternatives considered
A CLI-side fix (a fail-on-render-error flag on the @angular/build prerender builder) would also stop the broken page from shipping, but the error is swallowed one layer earlier, in @angular/core's ErrorHandler during ApplicationRef.tick, so raising it there is the more central fix and also covers plain SSR, not only the prerender builder. That is why this is filed here and not on angular-cli.