Skip to content

Commit 06452af

Browse files
alan-agius4alxhub
authored andcommitted
fix(platform-server): remove dependency on @angular/platform-browser-dynamic (#50064)
Using `@angular/platform-browser-dynamic` is no longer required for JIT scenarios with Ivy. Instead `@angular/compiler` should be imported instead. This change is part of the effort to reduce the server bundles sizes, which is needed to support cloud workers. BREAKING CHANGE: Users that are using SSR with JIT mode will now need to add `import to @angular/compiler` before bootstrapping the application. **NOTE:** this does not effect users using the Angular CLI. PR Close #50064
1 parent f49c6d0 commit 06452af

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

aio/content/guide/deprecations.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ v16 - v19
118118
| `@angular/common` | `isPlatformWorkerApp` and `isPlatformWorkerUi` | v16 | v18 |
119119
| `@angular/core` | `EnvironmentInjector.runInContext` | v16 | v18 |
120120
| `@angular/platform-server` | [`PlatformConfig.baseUrl` and `PlatformConfig.useAbsoluteUrl` config options](api/platform-server/PlatformConfig) | v16 | v18 |
121+
| `@angular/platform-server` | [`platformDynamicServer`](api/platform-server/platformDynamicServer) | v16 | v18 |
121122
| `@angular/platform-browser` | [`BrowserModule.withServerTransition`](api/platform-browser/BrowserModule#withservertransition) | v16 | v18 |
122123
| `@angular/platform-browser` | [`makeStateKey`, `StateKey` and `TransferState`](#platform-browser), symbols were moved to `@angular/core` | v16 | v18 |
123124

@@ -225,6 +226,9 @@ In the [API reference section](api) of this site, deprecated APIs are indicated
225226
|:--- |:--- |:--- |:--- |
226227
| [`ServerTransferStateModule`](api/platform-server/ServerTransferStateModule) | No replacement needed. | v14.1 | The `TransferState` class is available for injection without importing additional modules during server side rendering, when `ServerModule` is imported or `renderApplication` function is used for bootstrap. |
227228
| [`PlatformConfig.baseUrl` and `PlatformConfig.useAbsoluteUrl` config options](api/platform-server/PlatformConfig) | none | v16 | This was previously unused. |
229+
| [`platformDynamicServer`](api/platform-server/platformDynamicServer) | Import `@angular/compiler` and replace the usage with `platformServer` instead. | v16 | This is done to decrease the server bundle size for AOT builds. |
230+
231+
228232
<a id="forms"></a>
229233

230234
### &commat;angular/forms

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface PlatformConfig {
3333
useAbsoluteUrl?: boolean;
3434
}
3535

36-
// @public
36+
// @public @deprecated
3737
export const platformDynamicServer: (extraProviders?: StaticProvider[] | undefined) => PlatformRef;
3838

3939
// @public (undocumented)

packages/platform-server/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ ng_module(
2121
"//packages/compiler",
2222
"//packages/core",
2323
"//packages/platform-browser",
24-
"//packages/platform-browser-dynamic",
2524
"//packages/platform-browser/animations",
2625
"//packages/zone.js/lib:zone_d_ts",
2726
"@npm//@types/node",

packages/platform-server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"@angular/common": "0.0.0-PLACEHOLDER",
1313
"@angular/compiler": "0.0.0-PLACEHOLDER",
1414
"@angular/core": "0.0.0-PLACEHOLDER",
15-
"@angular/platform-browser": "0.0.0-PLACEHOLDER",
16-
"@angular/platform-browser-dynamic": "0.0.0-PLACEHOLDER"
15+
"@angular/platform-browser": "0.0.0-PLACEHOLDER"
1716
},
1817
"dependencies": {
1918
"tslib": "^2.3.0",

packages/platform-server/src/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {DOCUMENT, PlatformLocation, ViewportScroller, ɵgetDOM as getDOM, ɵNull
1010
import {HttpClientModule} from '@angular/common/http';
1111
import {createPlatformFactory, Injector, NgModule, Optional, PLATFORM_ID, PLATFORM_INITIALIZER, platformCore, PlatformRef, Provider, StaticProvider, Testability, ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS, ɵsetDocument, ɵTESTABILITY as TESTABILITY} from '@angular/core';
1212
import {BrowserModule, EVENT_MANAGER_PLUGINS} from '@angular/platform-browser';
13-
import {ɵplatformCoreDynamic as platformCoreDynamic} from '@angular/platform-browser-dynamic';
1413
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1514

1615
import {DominoAdapter, parseDocument} from './domino_adapter';
@@ -89,7 +88,9 @@ export const platformServer: (extraProviders?: StaticProvider[]|undefined) => Pl
8988
/**
9089
* The server platform that supports the runtime compiler.
9190
*
91+
* @see `platformServer`
92+
* @deprecated add an `import @angular/compiler` and replace the usage with `platformServer`
93+
* instead.
9294
* @publicApi
9395
*/
94-
export const platformDynamicServer =
95-
createPlatformFactory(platformCoreDynamic, 'serverDynamic', INTERNAL_SERVER_PLATFORM_PROVIDERS);
96+
export const platformDynamicServer = platformServer;

packages/platform-server/src/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ApplicationRef, InjectionToken, PlatformRef, Provider, Renderer2, Static
1010
import {first} from 'rxjs/operators';
1111

1212
import {PlatformState} from './platform_state';
13-
import {platformDynamicServer, platformServer} from './server';
13+
import {platformServer} from './server';
1414
import {BEFORE_APP_SERIALIZED, INITIAL_CONFIG} from './tokens';
1515

1616
interface PlatformOptions {
@@ -25,9 +25,7 @@ interface PlatformOptions {
2525
*/
2626
function createServerPlatform(options: PlatformOptions): PlatformRef {
2727
const extraProviders = options.platformProviders ?? [];
28-
const platformFactory =
29-
(typeof ngJitMode === 'undefined' || ngJitMode) ? platformDynamicServer : platformServer;
30-
return platformFactory([
28+
return platformServer([
3129
{provide: INITIAL_CONFIG, useValue: {document: options.document, url: options.url}},
3230
extraProviders
3331
]);

packages/platform-server/test/integration_spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import '@angular/compiler';
89

910
import {animate, AnimationBuilder, state, style, transition, trigger} from '@angular/animations';
1011
import {DOCUMENT, isPlatformServer, PlatformLocation, ɵgetDOM as getDOM} from '@angular/common';
@@ -14,7 +15,7 @@ import {ApplicationConfig, ApplicationRef, Component, destroyPlatform, Environme
1415
import {InitialRenderPendingTasks} from '@angular/core/src/initial_render_pending_tasks';
1516
import {TestBed} from '@angular/core/testing';
1617
import {bootstrapApplication, BrowserModule, provideClientHydration, Title, withNoDomReuse, withNoHttpTransferCache} from '@angular/platform-browser';
17-
import {BEFORE_APP_SERIALIZED, INITIAL_CONFIG, platformDynamicServer, PlatformState, provideServerRendering, renderModule, ServerModule} from '@angular/platform-server';
18+
import {BEFORE_APP_SERIALIZED, INITIAL_CONFIG, platformServer, PlatformState, provideServerRendering, renderModule, ServerModule} from '@angular/platform-server';
1819
import {provideRouter, RouterOutlet, Routes} from '@angular/router';
1920
import {Observable} from 'rxjs';
2021
import {first} from 'rxjs/operators';
@@ -536,7 +537,7 @@ describe('platform-server integration', () => {
536537

537538
it('should bootstrap', async () => {
538539
const platform =
539-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
540+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
540541

541542
const moduleRef = await platform.bootstrapModule(ExampleModule);
542543
expect(isPlatformServer(moduleRef.injector.get(PLATFORM_ID))).toBe(true);
@@ -552,10 +553,10 @@ describe('platform-server integration', () => {
552553

553554
it('should allow multiple platform instances', async () => {
554555
const platform =
555-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
556+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
556557

557558
const platform2 =
558-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
559+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
559560

560561

561562
await platform.bootstrapModule(ExampleModule).then((moduleRef) => {
@@ -572,7 +573,7 @@ describe('platform-server integration', () => {
572573
});
573574

574575
it('adds title to the document using Title service', async () => {
575-
const platform = platformDynamicServer([{
576+
const platform = platformServer([{
576577
provide: INITIAL_CONFIG,
577578
useValue: {document: '<html><head><title></title></head><body><app></app></body></html>'}
578579
}]);
@@ -586,7 +587,7 @@ describe('platform-server integration', () => {
586587
});
587588

588589
it('should get base href from document', async () => {
589-
const platform = platformDynamicServer([{
590+
const platform = platformServer([{
590591
provide: INITIAL_CONFIG,
591592
useValue: {document: '<html><head><base href="/"></head><body><app></app></body></html>'}
592593
}]);
@@ -597,7 +598,7 @@ describe('platform-server integration', () => {
597598
});
598599

599600
it('adds styles with ng-app-id attribute', async () => {
600-
const platform = platformDynamicServer([{
601+
const platform = platformServer([{
601602
provide: INITIAL_CONFIG,
602603
useValue: {document: '<html><head></head><body><app></app></body></html>'}
603604
}]);
@@ -612,7 +613,7 @@ describe('platform-server integration', () => {
612613

613614
it('copies known properties to attributes', async () => {
614615
const platform =
615-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
616+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
616617
const ref = await platform.bootstrapModule(ImageExampleModule);
617618
const appRef: ApplicationRef = ref.injector.get(ApplicationRef);
618619
const app = appRef.components[0].location.nativeElement;
@@ -623,14 +624,14 @@ describe('platform-server integration', () => {
623624
describe('PlatformLocation', () => {
624625
it('is injectable', async () => {
625626
const platform =
626-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
627+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
627628
const appRef = await platform.bootstrapModule(ExampleModule);
628629
const location = appRef.injector.get(PlatformLocation);
629630
expect(location.pathname).toBe('/');
630631
platform.destroy();
631632
});
632633
it('is configurable via INITIAL_CONFIG', async () => {
633-
const platform = platformDynamicServer([{
634+
const platform = platformServer([{
634635
provide: INITIAL_CONFIG,
635636
useValue: {document: '<app></app>', url: 'http://test.com/deep/path?query#hash'}
636637
}]);
@@ -644,7 +645,7 @@ describe('platform-server integration', () => {
644645
});
645646

646647
it('parses component pieces of a URL', async () => {
647-
const platform = platformDynamicServer([{
648+
const platform = platformServer([{
648649
provide: INITIAL_CONFIG,
649650
useValue: {document: '<app></app>', url: 'http://test.com:80/deep/path?query#hash'}
650651
}]);
@@ -661,7 +662,7 @@ describe('platform-server integration', () => {
661662
});
662663

663664
it('handles empty search and hash portions of the url', async () => {
664-
const platform = platformDynamicServer([{
665+
const platform = platformServer([{
665666
provide: INITIAL_CONFIG,
666667
useValue: {document: '<app></app>', url: 'http://test.com/deep/path'}
667668
}]);
@@ -676,7 +677,7 @@ describe('platform-server integration', () => {
676677

677678
it('pushState causes the URL to update', async () => {
678679
const platform =
679-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
680+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
680681

681682
const appRef = await platform.bootstrapModule(ExampleModule);
682683
const location = appRef.injector.get(PlatformLocation);
@@ -688,7 +689,7 @@ describe('platform-server integration', () => {
688689

689690
it('allows subscription to the hash state', done => {
690691
const platform =
691-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
692+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
692693
platform.bootstrapModule(ExampleModule).then(appRef => {
693694
const location: PlatformLocation = appRef.injector.get(PlatformLocation);
694695
expect(location.pathname).toBe('/');
@@ -715,8 +716,7 @@ describe('platform-server integration', () => {
715716
});
716717

717718
it('using long form should work', async () => {
718-
const platform =
719-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: doc}}]);
719+
const platform = platformServer([{provide: INITIAL_CONFIG, useValue: {document: doc}}]);
720720

721721
const moduleRef = await platform.bootstrapModule(AsyncServerModule);
722722
const applicationRef = moduleRef.injector.get(ApplicationRef);
@@ -1118,14 +1118,14 @@ describe('platform-server integration', () => {
11181118
describe('HttpClient', () => {
11191119
it('can inject HttpClient', async () => {
11201120
const platform =
1121-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
1121+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
11221122
const ref = await platform.bootstrapModule(HttpClientExampleModule);
11231123
expect(ref.injector.get(HttpClient) instanceof HttpClient).toBeTruthy();
11241124
});
11251125

11261126
it('can make HttpClient requests', async () => {
11271127
const platform =
1128-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
1128+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
11291129
await platform.bootstrapModule(HttpClientExampleModule).then(ref => {
11301130
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
11311131
const http = ref.injector.get(HttpClient);
@@ -1141,7 +1141,7 @@ describe('platform-server integration', () => {
11411141

11421142
it('can use HttpInterceptor that injects HttpClient', async () => {
11431143
const platform =
1144-
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
1144+
platformServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
11451145
await platform.bootstrapModule(HttpInterceptorExampleModule).then(ref => {
11461146
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
11471147
const http = ref.injector.get(HttpClient);

0 commit comments

Comments
 (0)