8000 fix(platform-browser-dynamic): ensure compiler is loaded before `@ang… · angular/angular@1e06c8e · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e06c8e

Browse files
devversionpkozlowski-opensource
authored andcommitted
fix(platform-browser-dynamic): ensure compiler is loaded before @angular/common (#60458)
With the recent changes to the APF bundling rules, we turned on tree-shaking in rollup to support proper code splitting for FESM bundles. This resulted in Rollup re-ordering imports in the FESM bundles of `@angular/platform-browser-dynamic`— highlighting that over the past years, this package "accidentally" resulted in the side-effects of the compiler registering itself globally. This continues to be the case, and our changes generally didn't cause any issues in CLI applications because the CLI explicitly wires up the compiler (as expected) before `-dynamic` is even loaded. For custom setup, like Analog, this order change surfaced a breakage because e.g. `@angular/common` with its JIT decorators of e.g. directives/services are triggered before the compiler is actually loaded/made available. This commit fixes this. The explicit imports in practice are a noop because our FESM bundling doesn't recognize compiler as side-effects true; but marking the whole -dynamic package as having side-effects; prevents rollup from swapping the import order. Long-term, we should look into improving this by teaching `ng_package` that e.g. the compiler has side-effects; so that the `import @angular/compiler` statement is not dropped when constructing FESM bundles. PR Close #60458
1 parent 13a8709 commit 1e06c8e

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

packages/platform-browser-dynamic/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ng_package(
2525
srcs = [
2626
"package.json",
2727
],
28+
side_effect_entry_points = [
29+
"@angular/platform-browser-dynamic",
30+
"@angular/platform-browser-dynamic/testing",
31+
],
2832
tags = [
2933
"release-with-framework",
3034
],

packages/platform-browser-dynamic/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
"ng-update": {
2525
"packageGroup": "NG_UPDATE_PACKAGE_GROUP"
2626
},
27-
"sideEffects": false
27+
"sideEffects": [
28+
"./fesm2022/platform-browser-dynamic.mjs",
29+
"./fesm2022/testing.mjs"
30+
]
2831
}

packages/platform-browser-dynamic/public_api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
* @description
1212
* Entry point for all public APIs of this package.
1313
*/
14+
15+
// Note: Historically people relied on `platform-browser-dynamic` magically
16+
// exposing the compiler for JIT. This is now made more explicit via this import.
17+
import '@angular/compiler';
18+
1419
export * from './src/platform-browser-dynamic';
1520

1621
// This file only reexports content of the `src` folder. Keep it that way.

packages/platform-browser-dynamic/testing/public_api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
* @description
1212
* Entry point for all public APIs of this package.
1313
*/
14+
15+
// Note: Historically people relied on `platform-browser-dynamic` magically
16+
// exposing the compiler for JIT. This is now made more explicit via this import.
17+
import '@angular/compiler';
18+
1419
export * from './src/testing';

0 commit comments

Comments
 (0)
0