From 71b3de8364f9af88a7706d3abb7dad24ed2827cc Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 4 Nov 2024 07:58:51 +0000 Subject: [PATCH] fix(@angular/build): ensure accurate content size in server asset metadata Updated the calculation to use `Buffer.byteLength()` for determining the length of escaped file content. This change ensures that the `size` property in server asset metadata accurately represents the length of the escaped content. --- .../angular/build/src/utils/server-rendering/manifest.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/angular/build/src/utils/server-rendering/manifest.ts b/packages/angular/build/src/utils/server-rendering/manifest.ts index eb13be07e5d1..505eeb0ed516 100644 --- a/packages/angular/build/src/utils/server-rendering/manifest.ts +++ b/packages/angular/build/src/utils/server-rendering/manifest.ts @@ -124,16 +124,19 @@ export function generateAngularServerAppManifest( const extension = extname(file.path); if (extension === '.html' || (inlineCriticalCss && extension === '.css')) { const jsChunkFilePath = `assets-chunks/${file.path.replace(/[./]/g, '_')}.mjs`; + const escapedContent = escapeUnsafeChars(file.text); + serverAssetsChunks.push( createOutputFile( jsChunkFilePath, - `export default \`${escapeUnsafeChars(file.text)}\`;`, + `export default \`${escapedContent}\`;`, BuildOutputFileType.ServerApplication, ), ); + const contentLength = Buffer.byteLength(escapedContent); serverAssetsContent.push( - `['${file.path}', {size: ${file.size}, hash: '${file.hash}', text: () => import('./${jsChunkFilePath}').then(m => m.default)}]`, + `['${file.path}', {size: ${contentLength}, hash: '${file.hash}', text: () => import('./${jsChunkFilePath}').then(m => m.default)}]`, ); } }