Skip to content

Commit

Permalink
fix(@angular/build): ensure index.csr.html is always generated when…
Browse files Browse the repository at this point in the history
… prerendering or SSR are enabled

This commit addresses an issue where `index.csr.html` was not being generated when SSR was disabled and prerendering was enabled.

Closes #28580
  • Loading branch information
alan-agius4 committed Oct 9, 2024
1 parent da858af commit 7c50ba9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/angular/build/src/builders/application/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,16 @@ export async function normalizeOptions(
* If SSR is activated, create a distinct entry file for the `index.html`.
* This is necessary because numerous server/cloud providers automatically serve the `index.html` as a static file
* if it exists (handling SSG).
*
* For instance, accessing `foo.com/` would lead to `foo.com/index.html` being served instead of hitting the server.
*
* This approach can also be applied to service workers, where the `index.csr.html` is served instead of the prerendered `index.html`.
*/
const indexBaseName = path.basename(options.index);
indexOutput = ssrOptions && indexBaseName === 'index.html' ? INDEX_HTML_CSR : indexBaseName;
indexOutput =
(ssrOptions || prerenderOptions) && indexBaseName === 'index.html'
? INDEX_HTML_CSR
: indexBaseName;
} else {
indexOutput = options.index.output || 'index.html';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ export default async function () {
return;
}

await ng('build', projectName, '--configuration=production', '--prerender');
await ng('build', projectName, '--configuration=production', '--prerender', '--no-ssr');
await runExpects();

// Test also JIT mode.
await ng('build', projectName, '--configuration=development', '--prerender', '--no-aot');
await ng(
'build',
projectName,
'--configuration=development',
'--prerender',
'--no-ssr',
'--no-aot',
);

await runExpects();

async function runExpects(): Promise<void> {
Expand All @@ -136,6 +144,10 @@ export default async function () {
'lazy-two/index.html': 'lazy-two works!',
};

if (!useWebpackBuilder) {
expects['index.csr.html'] = '<app-root></app-root>';
}

const distPath = 'dist/' + projectName + '/browser';
for (const [filePath, fileMatch] of Object.entries(expects)) {
await expectFileToMatch(join(distPath, filePath), fileMatch);
Expand Down

0 comments on commit 7c50ba9

Please sign in to comment.