Skip to content

Conversation

alan-agius4
Copy link
Contributor

This commit introduces a number of changes to the server bootstrapping process to make it more robust and less error-prone, especially for concurrent requests.

Previously, the server rendering process relied on a module-level global platform injector. This could lead to issues in server-side rendering environments where multiple requests are processed concurrently, as they could inadvertently share or overwrite the global injector state.

To address this, the bootstrapping process now explicitly passes the platformInjector through the bootstrapServerApplication and renderApplication functions. This ensures that each server-side render has its own isolated platform injector, preventing state leakage between requests.

The bootstrapApplication function will now throw an error when used on the server. Instead, developers should use the newly introduced bootstrapServerApplication function from @angular/platform-server.

In addition, getPlatform() and destroyPlatform() will now return null and be a no-op respectively when running in a server environment.

BREAKING CHANGE:

  • bootstrapApplication can no longer be used on the server. Instead, bootstrapServerApplication from @angular/platform-server should be used.

  • renderApplication now requires the return value of bootstrapServerApplication.

  • getPlatform() and destroyPlatform() are now no-ops on the server and getPlatform() will return null.

@alan-agius4 alan-agius4 changed the title feat(server): update server bootstrap API feat(platform-server): update server bootstrap API Sep 3, 2025
@angular-robot angular-robot bot added detected: breaking change PR contains a commit with a breaking change detected: feature PR contains a feature commit area: server Issues related to server-side rendering labels Sep 3, 2025
@ngbot ngbot bot modified the milestone: Backlog Sep 3, 2025
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 93d4db6 to a2d0427 Compare September 3, 2025 06:51
@alan-agius4 alan-agius4 added the target: major This PR is targeted for the next major release label Sep 3, 2025
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch 4 times, most recently from b705644 to 6947b29 Compare September 3, 2025 09:19
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 3, 2025
@alan-agius4 alan-agius4 marked this pull request as ready for review September 3, 2025 09:23
@pullapprove pullapprove bot requested a review from josephperrott September 3, 2025 09:23
@alan-agius4
Copy link
Contributor Author

alan-agius4 commented Sep 3, 2025

caretaker note: this requires a separate patch in G3 http://cl/802466606

@alan-agius4 alan-agius4 added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Sep 3, 2025
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 6947b29 to 837b218 Compare September 3, 2025 09:45
* Having a separate symbol for the module boostrap implementation allows us to
* tree shake the module based boostrap implementation in standalone apps.
* Having a separate symbol for the module bootstrap implementation allows us to
* tree shake the module based bootstrap implementation in standalone apps.
Copy link
Contributor

Choose a reason for hiding this comment

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

So much less scary without all the "boos"!

(Thanks for cleaning these up!)

@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from f93674e to 3615fd4 Compare September 4, 2025 06:56
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

Reviewed-for: dev-infra

@@ -45,7 +50,7 @@ export class PlatformState {
export function provideServerRendering(): EnvironmentProviders;

// @public
export function renderApplication<T>(bootstrap: () => Promise<ApplicationRef>, options: {
export function renderApplication(bootstrap: ReturnType<typeof bootstrapServerApplication>, options: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious how would this be rendered on ADEV. As an option, we can introduce a new type here.

Copy link
Contributor Author

@alan-agius4 alan-agius4 Sep 5, 2025

Choose a reason for hiding this comment

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

Comment on lines +5 to 7
const bootstrap = bootstrapServerApplication(AppComponent, config);

export default bootstrap;
Copy link
Contributor

Choose a reason for hiding this comment

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

For the generated code, can we just do this or it's better to have a const?

export default bootstrapServerApplication(AppComponent, config);

Copy link
Contributor Author

@alan-agius4 alan-agius4 Sep 5, 2025

Choose a reason for hiding this comment

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

Yeah we can, although I did not change it in the existing code.

This commit introduces a number of changes to the server bootstrapping process to make it more robust and less error-prone, especially for concurrent requests.

Previously, the server rendering process relied on a module-level global platform injector. This could lead to issues in server-side rendering environments where multiple requests are processed concurrently, as they could inadvertently share or overwrite the global injector state.

To address this, the bootstrapping process now explicitly passes the `platformInjector` through the `bootstrapServerApplication` and `renderApplication` functions. This ensures that each server-side render has its own isolated platform injector, preventing state leakage between requests.

The `bootstrapApplication` function will now throw an error when used on the server. Instead, developers should use the newly introduced `bootstrapServerApplication` function from `@angular/platform-server`.

In addition, `getPlatform()` and `destroyPlatform()` will now return `null` and be a no-op respectively when running in a server environment.

BREAKING CHANGE:
- `bootstrapApplication` can no longer be used on the server. Instead, `bootstrapServerApplication` from `@angular/platform-server` should be used.

- `renderApplication` now requires the return value of `bootstrapServerApplication`.

- `getPlatform()` and `destroyPlatform()` are now no-ops on the server and `getPlatform()` will return `null`.
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 9dce5cf to 8dab173 Compare September 5, 2025 09:31
Copy link

github-actions bot commented Sep 5, 2025

Deployed adev-preview for 697d3a8 to: https://ng-dev-previews-fw--pr-angular-angular-63562-adev-prev-fbt65dr2.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch 3 times, most recently from 669792e to 697d3a8 Compare September 5, 2025 11:25
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 697d3a8 to 4ce8bc6 Compare September 5, 2025 12:25
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 4ce8bc6 to ff571e6 Compare September 5, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer area: server Issues related to server-side rendering detected: breaking change PR contains a commit with a breaking change detected: feature PR contains a feature commit merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants