Skip to content

Commit 7c50ba9

Browse files
committed
fix(@angular/build): ensure index.csr.html is always generated when 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
1 parent da858af commit 7c50ba9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/angular/build/src/builders/application/options.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,16 @@ export async function normalizeOptions(
320320
* If SSR is activated, create a distinct entry file for the `index.html`.
321321
* This is necessary because numerous server/cloud providers automatically serve the `index.html` as a static file
322322
* if it exists (handling SSG).
323+
*
323324
* For instance, accessing `foo.com/` would lead to `foo.com/index.html` being served instead of hitting the server.
325+
*
326+
* This approach can also be applied to service workers, where the `index.csr.html` is served instead of the prerendered `index.html`.
324327
*/
325328
const indexBaseName = path.basename(options.index);
326-
indexOutput = ssrOptions && indexBaseName === 'index.html' ? INDEX_HTML_CSR : indexBaseName;
329+
indexOutput =
330+
(ssrOptions || prerenderOptions) && indexBaseName === 'index.html'
331+
? INDEX_HTML_CSR
332+
: indexBaseName;
327333
} else {
328334
indexOutput = options.index.output || 'index.html';
329335
}

tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,19 @@ export default async function () {
118118
return;
119119
}
120120

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

124124
// Test also JIT mode.
125-
await ng('build', projectName, '--configuration=development', '--prerender', '--no-aot');
125+
await ng(
126+
'build',
127+
projectName,
128+
'--configuration=development',
129+
'--prerender',
130+
'--no-ssr',
131+
'--no-aot',
132+
);
133+
126134
await runExpects();
127135

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

147+
if (!useWebpackBuilder) {
148+
expects['index.csr.html'] = '<app-root></app-root>';
149+
}
150+
139151
const distPath = 'dist/' + projectName + '/browser';
140152
for (const [filePath, fileMatch] of Object.entries(expects)) {
141153
await expectFileToMatch(join(distPath, filePath), fileMatch);

0 commit comments

Comments
 (0)