Skip to content

Commit 3e9fed9

Browse files
committed
fix(@angular/build): set target for Rolldown dependency prebundling in Vite dev server
Rolldown dependency prebundling in Vite dev server did not receive target options, leaving native async/await in prebundled dependencies. When an application uses Zone.js, native async/await causes Zone.js context loss across await ticks. Additionally, passed target options are set as a single target string array as a temporary workaround for Rolldown issue #10633 (where multiple browser targets cause initialization errors). Fixes #33770
1 parent 04888ea commit 3e9fed9

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

packages/angular/build/src/builders/dev-server/vite/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,15 @@ export async function* serveWithVite(
389389
? browserOptions.polyfills
390390
: [browserOptions.polyfills];
391391

392-
const target = transformSupportedBrowsersToTargets(browsers);
393-
if (!isZonelessApp(polyfills)) {
394-
// Rolldown doesn't have an option to support Zone.js/async-await, so we need to support es2016.
395-
target.push('es2016');
396-
}
392+
// TODO(alanagius): This is a workaround for https://github.com/rolldown/rolldown/issues/10633
393+
const target = isZonelessApp(polyfills) ? ['es2022'] : ['es2016'];
394+
395+
// Once the above issue is fixed, uncomment the below code.
396+
// const target = transformSupportedBrowsersToTargets(browsers);
397+
// if (!isZonelessApp(polyfills)) {
398+
// // Rolldown doesn't have an option to support Zone.js/async-await, so we need to support es2016.
399+
// target.push('es2016');
400+
// }
397401

398402
let ssrMode: ServerSsrMode = ServerSsrMode.NoSsr;
399403
if (

packages/angular/build/src/builders/dev-server/vite/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ function createSsrConfig(
104104
prebundleLoaderExtensions: RolldownLoaderOption | undefined,
105105
thirdPartySourcemaps: boolean,
106106
define: ApplicationBuilderInternalOptions['define'],
107+
target: string[],
107108
): Vite.SSROptions {
108109
return {
109110
// Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
110111
noExternal: /.*/,
111112
// Exclude any Node.js built in module and provided dependencies (currently build defined externals)
112113
external: externalMetadata.explicitServer,
113114
optimizeDeps: getDepOptimizationConfig({
115+
target,
114116
// Only enable with caching since it causes prebundle dependencies to be cached
115117
disabled: serverOptions.prebundle === false,
116118
// Exclude any explicitly defined dependencies (currently build defined externals and node.js built-ins)
@@ -214,6 +216,7 @@ export async function setupServer(
214216
prebundleLoaderExtensions,
215217
thirdPartySourcemaps,
216218
define,
219+
target,
217220
),
218221
plugins: [
219222
createAngularSetupMiddlewaresPlugin({
@@ -239,6 +242,7 @@ export async function setupServer(
239242
],
240243
// Browser only optimizeDeps. (This does not run for SSR dependencies).
241244
optimizeDeps: getDepOptimizationConfig({
245+
target,
242246
// Only enable with caching since it causes prebundle dependencies to be cached
243247
disabled: serverOptions.prebundle === false,
244248
// Exclude any explicitly defined dependencies (currently build defined externals)

packages/angular/build/src/tools/vite/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type RolldownLoaderOption = Exclude<
4848
>['moduleTypes'];
4949

5050
export function getDepOptimizationConfig({
51+
target,
5152
disabled,
5253
exclude,
5354
include,
@@ -56,6 +57,7 @@ export function getDepOptimizationConfig({
5657
thirdPartySourcemaps,
5758
define = {},
5859
}: {
60+
target: string[];
5961
disabled: boolean;
6062
exclude: string[];
6163
include: string[];
@@ -73,6 +75,7 @@ export function getDepOptimizationConfig({
7375
noDiscovery: disabled,
7476
rolldownOptions: {
7577
transform: {
78+
target,
7679
define,
7780
},
7881
moduleTypes: loader,

0 commit comments

Comments
 (0)