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 angular#28580
  • Loading branch information
alan-agius4 committed Oct 8, 2024
1 parent 523c2c9 commit d466bbf
Show file tree
Hide file tree
Showing 2 changed files with 18 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,16 +118,25 @@ 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> {
const expects: Record<string, string> = {
'index.html': 'one works!',
'index.csr.html': '<app-root></app-root>',
'two/index.html': 'router-outlet',
'two/two-child-one/index.html': 'two-child-one works!',
'two/two-child-two/index.html': 'two-child-two works!',
Expand Down

0 comments on commit d466bbf

Please sign in to comment.