Skip to content

Conversation

alan-agius4
Copy link
Contributor

@alan-agius4 alan-agius4 commented Sep 8, 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.

(cherry picked from commit 8bf80c9)

@pullapprove pullapprove bot requested review from devversion and kirjs September 8, 2025 12:08
@alan-agius4 alan-agius4 marked this pull request as draft September 8, 2025 12:08
@alan-agius4 alan-agius4 added the target: lts This PR is targeting a version currently in long-term support label Sep 8, 2025
@alan-agius4 alan-agius4 force-pushed the 19.2-platform-injector branch from ecb4f27 to 3c17c4f Compare September 8, 2025 12:12
…ping

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.

(cherry picked from commit 8bf80c9)
@alan-agius4 alan-agius4 force-pushed the 19.2-platform-injector branch from 3c17c4f to db123d3 Compare September 8, 2025 12:41
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 8, 2025
@alan-agius4 alan-agius4 marked this pull request as ready for review September 8, 2025 12:57
@pullapprove pullapprove bot requested review from devversion September 8, 2025 12:57
@alan-agius4 alan-agius4 force-pushed the 19.2-platform-injector branch from b1edebf to db123d3 Compare September 8, 2025 13:25
Updates the `actions/checkout` and `angular/dev-infra/github-actions` to their latest versions in `.github/workflows/dev-infra.yml`.
@KrrishSR4

This comment was marked as spam.

@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 9, 2025
@alan-agius4
Copy link
Contributor Author

alan-agius4 commented Sep 9, 2025

caretaker note: please ignore the labels workflow failure and I cannot remove the pending review requests.

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.

LGTM

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 review from crisbeto and mmalerba September 9, 2025 16:50
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

Copy link
Contributor

@atscott atscott 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 atscott merged commit 70d0639 into angular:19.2.x Sep 9, 2025
25 of 29 checks passed
@alan-agius4 alan-agius4 deleted the 19.2-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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: lts This PR is targeting a version currently in long-term support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants