Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): app-shell generation incorrect co…
Browse files Browse the repository at this point in the history
…ntent when using the application builder

In some cases, the index.html file emitted contained the wrong contents. This because in OutputFiles there were present multiple files with the same name.

Closes #26593
  • Loading branch information
alan-agius4 authored and clydin committed Dec 6, 2023
1 parent b5b0432 commit e3ad8c4
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ export async function executePostBundleSteps(
*/
let indexContentOutputNoCssInlining: string | undefined;

// When using prerender/app-shell the index HTML file can be regenerated.
// Thus, we use a Map so that we do not generate 2 files with the same filename.
const additionalHtmlOutputFiles = new Map<string, BuildOutputFile>();

// Generate index HTML file
// If localization is enabled, index generation is handled in the inlining process.
// NOTE: Localization with SSR is not currently supported.
if (indexHtmlOptions) {
const { content, contentWithoutCriticalCssInlined, errors, warnings } = await generateIndexHtml(
initialFiles,
Expand All @@ -84,14 +87,17 @@ export async function executePostBundleSteps(
allErrors.push(...errors);
allWarnings.push(...warnings);

additionalOutputFiles.push(
additionalHtmlOutputFiles.set(
indexHtmlOptions.output,
createOutputFileFromText(indexHtmlOptions.output, content, BuildOutputFileType.Browser),
);

if (ssrOptions) {
additionalOutputFiles.push(
const serverIndexHtmlFilename = 'index.server.html';
additionalHtmlOutputFiles.set(
serverIndexHtmlFilename,
createOutputFileFromText(
'index.server.html',
serverIndexHtmlFilename,
contentWithoutCriticalCssInlined,
BuildOutputFileType.Server,
),
Expand Down Expand Up @@ -130,12 +136,15 @@ export async function executePostBundleSteps(
prerenderedRoutes.push(...Array.from(generatedRoutes));

for (const [path, content] of Object.entries(output)) {
additionalOutputFiles.push(
additionalHtmlOutputFiles.set(
path,
createOutputFileFromText(path, content, BuildOutputFileType.Browser),
);
}
}

additionalOutputFiles.push(...additionalHtmlOutputFiles.values());

// Augment the application with service worker support
// If localization is enabled, service worker is handled in the inlining process.
if (serviceWorker) {
Expand Down

0 comments on commit e3ad8c4

Please sign in to comment.