Skip to content

Commit 71b3de8

Browse files
committed
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.
1 parent d21e511 commit 71b3de8

File tree

1 file changed

+5
-2
lines changed
  • packages/angular/build/src/utils/server-rendering

1 file changed

+5
-2
lines changed

packages/angular/build/src/utils/server-rendering/manifest.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,19 @@ export function generateAngularServerAppManifest(
124124
const extension = extname(file.path);
125125
if (extension === '.html' || (inlineCriticalCss && extension === '.css')) {
126126
const jsChunkFilePath = `assets-chunks/${file.path.replace(/[./]/g, '_')}.mjs`;
127+
const escapedContent = escapeUnsafeChars(file.text);
128+
127129
serverAssetsChunks.push(
128130
createOutputFile(
129131
jsChunkFilePath,
130-
`export default \`${escapeUnsafeChars(file.text)}\`;`,
132+
`export default \`${escapedContent}\`;`,
131133
BuildOutputFileType.ServerApplication,
132134
),
133135
);
134136

137+
const contentLength = Buffer.byteLength(escapedContent);
135138
serverAssetsContent.push(
136-
`['${file.path}', {size: ${file.size}, hash: '${file.hash}', text: () => import('./${jsChunkFilePath}').then(m => m.default)}]`,
139+
`['${file.path}', {size: ${contentLength}, hash: '${file.hash}', text: () => import('./${jsChunkFilePath}').then(m => m.default)}]`,
137140
);
138141
}
139142
}

0 commit comments

Comments
 (0)