Repository navigation
fix(@angular/ssr): guard aborted requests across rendering and serialization - #34768
Open
alan-agius4 wants to merge 1 commit into
Open
alan-agius4 wants to merge 1 commit into
alan-agius4 wants to merge 1 commit into
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.
This was referenced Nov 20, 2026
Open
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.
dgp1130
approved these changes
Nov 20, 2026
| ) { | ||
| void destroy(); | ||
|
|
||
| return; |
Collaborator
There was a problem hiding this comment.
Question: Do we need to call reject in these cases? Seems like we're not doing that now, but feels weird to leave a dangling promise.
| ); | ||
|
|
||
| expect(result.hasNavigationError).toBeFalse(); | ||
| if (!('content' in result)) { |
Collaborator
There was a problem hiding this comment.
Suggestion: Prefer expect over if (...) { fail(...) }.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?