Skip to content

Commit 0ee493e

Browse files
SkyZeroZxalan-agius4
authored andcommitted
fix(@angular/build): generate a separate server chunk for each prerendered page
Server asset chunks were named after the page path with `.` and `/` replaced by `_`, so pages such as `blog/archive` and `blog_archive` shared one chunk and one of them was served in place of the other. Chunk paths now mirror the page path. Fixes #34722 (cherry picked from commit be9e3a0)
1 parent 9329952 commit 0ee493e

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ export async function generateAngularServerAppManifest(
170170
for (const file of [...additionalHtmlOutputFiles.values(), ...outputFiles]) {
171171
const extension = extname(file.path);
172172
if (extension === '.html') {
173-
const jsChunkFilePath = `assets-chunks/${file.path.replace(/[./]/g, '_')}.mjs`;
173+
// Mirror the asset path, which is unique, so that two assets never share a chunk.
174+
const jsChunkFilePath = `assets-chunks/${file.path}.mjs`;
174175
const escapedContent = escapeUnsafeChars(file.text);
175176

176177
serverAssetsChunks.push(

‎packages/angular/build/src/utils/server-rendering/manifest_spec.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,32 @@ describe('generateAngularServerAppManifest', () => {
192192
);
193193
});
194194

195+
it('should generate a separate chunk for each asset', async () => {
196+
const { manifestContent, serverAssetsChunks } = await generateManifest({
197+
'blog/archive/index.html': '<main>Archive</main>',
198+
'blog_archive/index.html': '<main>Landing</main>',
199+
'blog.archive/index.html': '<main>Release</main>',
200+
});
201+
202+
expect(serverAssetsChunks).toEqual([
203+
jasmine.objectContaining({
204+
path: 'assets-chunks/blog/archive/index.html.mjs',
205+
text: 'export default `<main>Archive</main>`;',
206+
}),
207+
jasmine.objectContaining({
208+
path: 'assets-chunks/blog_archive/index.html.mjs',
209+
text: 'export default `<main>Landing</main>`;',
210+
}),
211+
jasmine.objectContaining({
212+
path: 'assets-chunks/blog.archive/index.html.mjs',
213+
text: 'export default `<main>Release</main>`;',
214+
}),
215+
]);
216+
expect(manifestContent).toContain('import("./assets-chunks/blog/archive/index.html.mjs")');
217+
expect(manifestContent).toContain('import("./assets-chunks/blog_archive/index.html.mjs")');
218+
expect(manifestContent).toContain('import("./assets-chunks/blog.archive/index.html.mjs")');
219+
});
220+
195221
it('should serialize a base href which contains JavaScript string delimiters', async () => {
196222
const { manifestContent } = await generateManifest(
197223
{ 'index.html': '<main></main>' },

0 commit comments

Comments
 (0)