Repository navigation
fix(@angular/ssr): guard aborted requests across rendering and serialization - #34768
Conversation
…ization Short-circuit `AngularServerApp.handleRendering()` on `request.signal.aborted` before asset reads, `html:transform:pre` hooks, `renderAngular()`, and critical CSS inlining so aborted requests avoid unnecessary work. In `renderAngular()`, check `moduleRef.injector.destroyed`, `applicationRef.destroyed`, `platformRef.destroyed`, and `destroyPromise` consistently across bootstrap, `whenStable()`, and `content()`, clear `renderTimeoutId` on every `destroy()` call, detach abort listeners before settling `content()`, and ensure `asyncDestroyPlatform()` always resolves.
There was a problem hiding this comment.
Code Review
This pull request introduces early abort checks using request.signal.aborted throughout the Angular SSR and CSR rendering lifecycles to prevent unnecessary processing when a client disconnects. It also improves platform destruction safety and adds comprehensive unit tests to verify abort behavior. The feedback suggests extending the abort checks to the CSR path after HTML transformations for consistency with the SSR path.
|
@alan-agius4 The process still ends with this changes and angular/angular#72139 merged. Repro on the https://github.com/SkyZeroZx/angular-ssr-abort-crash-lab/tree/destroy-hook-after-fixes It's the first example from the description plus an error handler, routed at npm ci
npx ng build
node tools/destroy-hook.mjsThe second case doesn't need an abort. The call fails, the app handles it, the subscription is never created, and the destroy at the end of the render throws. On The Express server from I opened #34777 to fix it |
PR Checklist
PR Type
What is the current behavior?
When a request is aborted during SSR rendering:
AngularServerApp.handleRendering()can still perform asset reads, runhtml:transform:prehooks, invokerenderAngular(), or run BeastiesinlineCriticalCss()afterrequest.signalhas already aborted.renderAngular()does not checkmoduleRef.injector.destroyed,applicationRef.destroyed,platformRef.destroyed(post-whenStable), ordestroyPromiseconsistently across bootstrap, stability, andcontent(), only clearsrenderTimeoutIdon the firstdestroy()call, detaches abort listeners two microtasks aftercontent()settles, and can leaveasyncDestroyPlatform()unresolved ifplatformRef.destroy()throws.Companion framework fix: angular/angular#72139
Related issue: #34754
What is the new behavior?
AngularServerApp.handleRendering()onrequest.signal.abortedbefore asset reads,html:transform:prehooks,renderAngular(), redirect response creation, and critical CSS inlining, and uniformly awaitresult.destroy()when aborting inside the responseReadableStream.renderAngular()(relying on the framework teardown fixes in fix(core): safely handle server platform destruction on aborted SSR requests angular#72139 instead of deferring destruction or adding fallback timeouts).moduleRef.injector.destroyed,applicationRef.destroyed,platformRef.destroyed, anddestroyPromiseconsistently acrossrenderAngular()andcontent(), clearrenderTimeoutIdon everydestroy()call, detach abort listeners before settlingcontent(), and wrapplatformRef.destroy()intry/finallyinsideasyncDestroyPlatform().Does this PR introduce a breaking change?