Skip to content

Commit

Permalink
fix(@angular/build): ensure accurate content size in server asset met…
Browse files Browse the repository at this point in the history
…adata

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.
  • Loading branch information
alan-agius4 committed Nov 4, 2024
1 parent d21e511 commit 71b3de8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/angular/build/src/utils/server-rendering/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}]`,
);
}
}
Expand Down

0 comments on commit 71b3de8

Please sign in to comment.