Skip to content

Conversation

alan-agius4
Copy link
Contributor

@alan-agius4 alan-agius4 commented Sep 3, 2025

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.

The new approach introduces a BootstrapContext that is passed to the bootstrapApplication function. This context provides a platform reference that is scoped to the individual request, ensuring that each server-side render has an isolated platform injector. This prevents state leakage between concurrent requests and makes the overall process more reliable.

BREAKING CHANGE:
The server-side bootstrapping process has been changed to eliminate the reliance on a global platform injector.

Before:

const bootstrap = () => bootstrapApplication(AppComponent, config);

After:

const bootstrap = (context: BootstrapContext) =>
  bootstrapApplication(AppComponent, config, context);

A schematic is provided to automatically update main.server.ts files to pass the BootstrapContext to the bootstrapApplication call.

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

@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
@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

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 2 times, most recently from 3776c96 to 669792e Compare September 5, 2025 11:24
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 669792e to 697d3a8 Compare September 5, 2025 11:25
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch 3 times, most recently from ff571e6 to b6e92f0 Compare September 8, 2025 08:36
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Sep 8, 2025
@alan-agius4 alan-agius4 changed the title feat(platform-server): update server bootstrap API feat(core): introduce BootstrapContext for improved server bootstrapping Sep 8, 2025
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch 3 times, most recently from f092235 to 8bf80c9 Compare September 8, 2025 09:27
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, just a few minor comments.

…pping

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.

The new approach introduces a `BootstrapContext` that is passed to the `bootstrapApplication` function. This context provides a platform reference that is scoped to the individual request, ensuring that each server-side render has an isolated platform injector. This prevents state leakage between concurrent requests and makes the overall process more reliable.

BREAKING CHANGE:
The server-side bootstrapping process has been changed to eliminate the reliance on a global platform injector.

Before:
```ts
const bootstrap = () => bootstrapApplication(AppComponent, config);
```

After:
```ts
const bootstrap = (context: BootstrapContext) =>
  bootstrapApplication(AppComponent, config, context);
```

A schematic is provided to automatically update `main.server.ts` files to pass the `BootstrapContext` to the `bootstrapApplication` call.

In addition, `getPlatform()` and `destroyPlatform()` will now return `null` and be a no-op respectively when running in a server environment.
@alan-agius4 alan-agius4 force-pushed the main-platform-injector branch from 48f1cc0 to 0911822 Compare September 9, 2025 06:44
Copy link
Contributor

@AndrewKushnir AndrewKushnir 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: public-api

@pullapprove pullapprove bot requested a review from crisbeto September 9, 2025 16:37
Copy link
Contributor

@jkrems jkrems 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: public-api

@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 Sep 9, 2025
@atscott
Copy link
Contributor

atscott commented Sep 9, 2025

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

@atscott atscott closed this in 28926ba Sep 9, 2025
@alan-agius4 alan-agius4 deleted the main-platform-injector branch September 9, 2025 17:58
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: core Issues related to the framework runtime 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.

6 participants