Skip to content

Commit cccc91b

Browse files
committed
fix(@angular/build): avoid extra tick in SSR dev-server builds
In SSR applications, an unnecessary event loop tick during server startup could lead to an incorrect platform being initialized. This change introduces an `ngJitMode` define, which is set to `false` during AOT builds. This allows for the JIT-specific code paths to not be followed, preventing the async operations that caused the extra tick. This ensures that the server platform is correctly and synchronously initialized.
1 parent 700e6bc commit cccc91b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export async function* serveWithVite(
320320
extensions?.middleware,
321321
transformers?.indexHtml,
322322
thirdPartySourcemaps,
323+
!!browserOptions.aot,
323324
);
324325

325326
server = await createServer(serverConfiguration);
@@ -503,6 +504,7 @@ export async function setupServer(
503504
extensionMiddleware?: Connect.NextHandleFunction[],
504505
indexHtmlTransformer?: (content: string) => Promise<string>,
505506
thirdPartySourcemaps = false,
507+
aot = false,
506508
): Promise<InlineConfig> {
507509
const proxy = await loadProxyConfiguration(
508510
serverOptions.workspaceRoot,
@@ -589,6 +591,7 @@ export async function setupServer(
589591
// Include all implict dependencies from the external packages internal option
590592
include: externalMetadata.implicitServer,
591593
ssr: true,
594+
aot,
592595
prebundleTransformer,
593596
zoneless,
594597
target,
@@ -625,6 +628,7 @@ export async function setupServer(
625628
zoneless,
626629
loader: prebundleLoaderExtensions,
627630
thirdPartySourcemaps,
631+
aot,
628632
}),
629633
};
630634

@@ -663,6 +667,7 @@ function getDepOptimizationConfig({
663667
ssr,
664668
loader,
665669
thirdPartySourcemaps,
670+
aot,
666671
}: {
667672
disabled: boolean;
668673
exclude: string[];
@@ -673,6 +678,7 @@ function getDepOptimizationConfig({
673678
zoneless: boolean;
674679
loader?: EsbuildLoaderOption;
675680
thirdPartySourcemaps: boolean;
681+
aot: boolean;
676682
}): DepOptimizationConfig {
677683
const plugins: ViteEsBuildPlugin[] = [
678684
{
@@ -704,6 +710,9 @@ function getDepOptimizationConfig({
704710
supported: getFeatureSupport(target, zoneless),
705711
plugins,
706712
loader,
713+
define: {
714+
'ngJitMode': aot ? 'false' : 'true',
715+
},
707716
resolveExtensions: ['.mjs', '.js', '.cjs'],
708717
},
709718
};

0 commit comments

Comments
 (0)