-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit a81c176
committed
feat(@angular/ssr): introduce BootstrapContext for isolated server-side rendering
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.1 parent e6a3b55 commit a81c176
File tree
6 files changed
+26
-17
lines changed- packages
- angular/ssr
- node/src/common-engine
- src
- routes
- utils
- schematics/angular/server/files
- application-builder/standalone-src
- server-builder/standalone-src
6 files changed
+26
-17
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7 | 7 |
| |
8 | 8 |
| |
9 | 9 |
| |
10 | + | ||
10 | 11 |
| |
11 | 12 |
| |
12 | 13 |
| |
| |||
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
26 | - | ||
27 | + | ||
27 | 28 |
| |
28 | 29 |
| |
29 | 30 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
634 | 634 |
| |
635 | 635 |
| |
636 | 636 |
| |
637 | - | ||
637 | + | ||
638 | 638 |
| |
639 | 639 |
| |
640 | 640 |
| |
|
Lines changed: 12 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
356 | 356 |
| |
357 | 357 |
| |
358 | 358 |
| |
359 | - | ||
359 | + | ||
360 | 360 |
| |
361 | 361 |
| |
362 | 362 |
| |
363 | 363 |
| |
364 | 364 |
| |
365 | - | ||
366 | - | ||
367 | - | ||
368 | - | ||
369 | - | ||
370 | - | ||
371 | - | ||
372 | - | ||
365 | + | ||
366 | + | ||
367 | + | ||
368 | + | ||
369 | + | ||
370 | + | ||
371 | + | ||
372 | + | ||
373 | + | ||
374 | + | ||
375 | + | ||
373 | 376 |
| |
374 | 377 |
| |
375 | 378 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
17 | + | ||
17 | 18 |
| |
18 | 19 |
| |
19 | 20 |
| |
| |||
31 | 32 |
| |
32 | 33 |
| |
33 | 34 |
| |
34 | - | ||
35 | + | ||
36 | + | ||
37 | + | ||
35 | 38 |
| |
36 | 39 |
| |
37 | 40 |
| |
| |||
90 | 93 |
| |
91 | 94 |
| |
92 | 95 |
| |
93 | - | ||
96 | + | ||
94 | 97 |
| |
95 | 98 |
| |
96 | 99 |
| |
|
packages/schematics/angular/server/files/application-builder/standalone-src/main.server.ts.template
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | - | ||
1 | + | ||
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
5 | - | ||
5 | + | ||
6 | + | ||
6 | 7 |
| |
7 | 8 |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | - | ||
1 | + | ||
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
5 | - | ||
5 | + | ||
6 | + | ||
6 | 7 |
| |
7 | 8 |
|
0 commit comments