Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions modules/builders/src/prerender/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,11 @@ describe('Prerender Builder', () => {
]);
});

it('should write to "index/index.html" for route "/"', async () => {
it('should save index.html as index.original.html when caching route "/"', async () => {
await PrerenderModule._renderUniversal(options, context, browserResult, serverResult);
expect(mkdirSyncSpy.calls.allArgs()).toEqual([
['dist/browser/index', { recursive: true }],
]);
expect(writeFileSyncSpy.calls.allArgs()).toEqual([
['dist/browser/index/index.html', RENDERED_HTML],
['dist/browser/index.original.html', INITIAL_HTML],
['dist/browser/index.html', RENDERED_HTML],
]);
});

Expand All @@ -234,6 +232,7 @@ describe('Prerender Builder', () => {
mkdirSyncSpy.and.callFake(() => {
throw new Error('Test mkdirSync error.');
});
spyOn(context.logger, 'error');
await expectAsync(
PrerenderModule._renderUniversal(
options,
Expand All @@ -243,7 +242,7 @@ describe('Prerender Builder', () => {
)
).not.toBeRejected();
expect(mkdirSyncSpy).toHaveBeenCalled();
expect(writeFileSyncSpy).not.toHaveBeenCalled();
expect(context.logger.error).toHaveBeenCalled();
});
});

Expand Down
9 changes: 7 additions & 2 deletions modules/builders/src/prerender/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ export async function _renderUniversal(
};
const html = await renderModuleFn(AppServerModuleDef, renderOpts);

const outputFolderName = route === '/' ? 'index' : route;
const outputFolderPath = path.join(outputPath, outputFolderName);
const outputFolderPath = path.join(outputPath, route);
const outputIndexPath = path.join(outputFolderPath, 'index.html');

// This case happens when we are prerendering "/".
if (browserIndexOutputPath === outputIndexPath) {
const browserIndexOutputPathOriginal = path.join(outputPath, 'index.original.html');
fs.writeFileSync(browserIndexOutputPathOriginal, indexHtml);
}

// There will never conflicting output folders
// because items in options.routes must be unique.
try {
Expand Down