Skip to content

Commit 630af63

Browse files
alan-agius4alxhub
authored andcommitted
feat(platform-browser): deprecate withServerTransition call (#49422)
This commit deprecated ` BrowserModule.withServerTransition` instead `APP_ID` should be used instead to configure the app id. DEPRECATED: `BrowserModule.withServerTransition` has been deprecated. `APP_ID` should be used instead to set the application ID. NB: Unless, you render multiple Angular applications on the same page, setting an application ID is not necessary. Before: ```ts imports: [ BrowserModule.withServerTransition({ appId: 'serverApp' }), ... ] ``` After: ```ts imports: [ BrowserModule, { provide: APP_ID, useValue: 'serverApp' }, ... ], ``` PR Close #49422
1 parent 64067a1 commit 630af63

File tree

11 files changed

+51
-18
lines changed

11 files changed

+51
-18
lines changed

aio/content/guide/deprecations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ v16 - v19
100100
| `@angular/platform-server` | [`ServerTransferStateModule`](#platform-server) | v14 | v16 |
101101
| `@angular/service-worker` | [`SwUpdate#activated`](api/service-worker/SwUpdate#activated) | v13 | v16 |
102102
| `@angular/service-worker` | [`SwUpdate#available`](api/service-worker/SwUpdate#available) | v13 | v16 |
103+
| `@angular/platform-browser` | [`BrowserModule.withServerTransition`](api/platform-browser/BrowserModule#withservertransition) | v16 | v18 |
103104

104105
### Deprecated features that can be removed in v17 or later
105106

@@ -204,6 +205,7 @@ In the [API reference section](api) of this site, deprecated APIs are indicated
204205
| API | Replacement | Deprecation announced | Details |
205206
|:--- |:--- |:--- |:--- |
206207
| [`BrowserTransferStateModule`](api/platform-browser/BrowserTransferStateModule) | No replacement needed. | v14.1 | The `TransferState` class is available for injection without importing additional modules on the client side of a server-rendered application. |
208+
| [`BrowserModule.withServerTransition`](api/platform-browser/BrowserModule#withservertransition) | No replacement needed. | v16.0 | The `APP_ID`token should be used instead to set the application ID. |
207209

208210
<a id="platform-browser-dynamic"></a>
209211

goldens/public-api/platform-browser/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function bootstrapApplication(rootComponent: Type<unknown>, options?: App
3535
// @public
3636
export class BrowserModule {
3737
constructor(providersAlreadyPresent: boolean | null);
38+
// @deprecated
3839
static withServerTransition(params: {
3940
appId: string;
4041
}): ModuleWithProviders<BrowserModule>;

packages/core/src/application_tokens.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,38 @@ import {InjectionToken} from './di/injection_token';
1616
* BY default, the value is randomly generated and assigned to the application by Angular.
1717
* To provide a custom ID value, use a DI provider <!-- TODO: provider --> to configure
1818
* the root {@link Injector} that uses this token.
19+
* The token is needed in cases when multiple applications are bootstrapped on a page
20+
* (for example, using `bootstrapApplication` calls). In this case, ensure that those applications
21+
* have different `APP_ID` value setup. For example:
22+
*
23+
* ```
24+
* bootstrapApplication(ComponentA, {
25+
* providers: [
26+
* {provide: APP_ID, useValue: 'app-a'},
27+
* // ... other providers ...
28+
* ]
29+
* });
30+
*
31+
* bootstrapApplication(ComponentB, {
32+
* providers: [
33+
* {provide: APP_ID, useValue: 'app-b'},
34+
* // ... other providers ...
35+
* ]
36+
* });
37+
* ```
38+
*
39+
* By default, when there is only 1 application bootstrapped, you don't need to provide the `APP_ID`
40+
* token (the `ng` will be used as an app ID).
1941
*
2042
* @publicApi
2143
*/
2244
export const APP_ID = new InjectionToken<string>('AppId', {
2345
providedIn: 'root',
24-
factory: _appIdRandomProviderFactory,
46+
factory: () => DEFAULT_APP_ID,
2547
});
2648

27-
export function _appIdRandomProviderFactory() {
28-
return `${_randomChar()}${_randomChar()}${_randomChar()}`;
29-
}
30-
31-
/**
32-
* Providers that generate a random `APP_ID_TOKEN`.
33-
* @publicApi
34-
*/
35-
export const APP_ID_RANDOM_PROVIDER = {
36-
provide: APP_ID,
37-
useFactory: _appIdRandomProviderFactory,
38-
deps: <any[]>[],
39-
};
40-
41-
function _randomChar(): string {
42-
return String.fromCharCode(97 + Math.floor(Math.random() * 25));
43-
}
49+
/** Default value of the `APP_ID` token. */
50+
const DEFAULT_APP_ID = 'ng';
4451

4552
/**
4653
* A function that is executed when a platform is initialized.

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
{
159159
"name": "DASH_CASE_REGEXP"
160160
},
161+
{
162+
"name": "DEFAULT_APP_ID"
163+
},
161164
{
162165
"name": "DEFAULT_NOOP_PREVIOUS_NODE"
163166
},

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
{
8484
"name": "ConnectableSubscriber"
8585
},
86+
{
87+
"name": "DEFAULT_APP_ID"
88+
},
8689
{
8790
"name": "DI_DECORATOR_FLAG"
8891
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
{
117117
"name": "ControlContainer"
118118
},
119+
{
120+
"name": "DEFAULT_APP_ID"
121+
},
119122
{
120123
"name": "DEFAULT_VALUE_ACCESSOR"
121124
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
{
123123
"name": "ControlContainer"
124124
},
125+
{
126+
"name": "DEFAULT_APP_ID"
127+
},
125128
{
126129
"name": "DEFAULT_VALUE_ACCESSOR"
127130
},

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
{
141141
"name": "CreateUrlTreeUsingSnapshot"
142142
},
143+
{
144+
"name": "DEFAULT_APP_ID"
145+
},
143146
{
144147
"name": "DEFAULT_LOCALE_ID"
145148
},

packages/core/test/bundling/standalone_bootstrap/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
{
6969
"name": "ConnectableSubscriber"
7070
},
71+
{
72+
"name": "DEFAULT_APP_ID"
73+
},
7174
{
7275
"name": "DEFAULT_LOCALE_ID"
7376
},

packages/core/test/bundling/todo/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
{
8484
"name": "ConnectableSubscriber"
8585
},
86+
{
87+
"name": "DEFAULT_APP_ID"
88+
},
8689
{
8790
"name": "DI_DECORATOR_FLAG"
8891
},

0 commit comments

Comments
 (0)