From 1b59423571fd3d75f96db138425cb94ede7ac4fe Mon Sep 17 00:00:00 2001 From: Akash Patel <2557058+imaksp@users.noreply.github.com> Date: Thu, 6 Aug 2026 16:59:45 +0530 Subject: [PATCH] fix(@angular/build): count statically imported chunks in the initial total `optimizeChunks` removes every used chunk from `initialFiles` and then re-walks the optimized graph to restore the ones the main entry still imports statically. The walk builds an `InitialFileRecord` for each import but never stores it, so the entries are analyzed and then dropped. Because the records were deleted just above, `existingRecord` is always undefined, and the map ends up holding only the configured entry points. Chunks the browser must fetch before the application can run are therefore excluded from "Initial total" and reported under "Lazy chunk files" instead. On a large application this understated the initial payload by roughly 3x: 377.35 kB reported against 1.35 MB actually required, with a 919 kB statically imported chunk listed as lazy. `BundlerContext#bundle` performs the equivalent walk and does call `initialFiles.set` before pushing the entry; this aligns the optimizer with it. Fixes #33773 --- .../angular/build/src/builders/application/chunk-optimizer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/angular/build/src/builders/application/chunk-optimizer.ts b/packages/angular/build/src/builders/application/chunk-optimizer.ts index 7d7a6e56b829..2241a4204999 100644 --- a/packages/angular/build/src/builders/application/chunk-optimizer.ts +++ b/packages/angular/build/src/builders/application/chunk-optimizer.ts @@ -418,6 +418,7 @@ export async function optimizeChunks( const record = createInitialFileRecord(entryRecord.depth + 1); + original.initialFiles.set(importPath, record); entriesToAnalyze.push([importPath, record]); } }