mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
Fix prerendering with unused dynamic chunks (#11387)
This commit is contained in:
parent
cb4e6d09de
commit
b498461e27
6 changed files with 23 additions and 5 deletions
5
.changeset/giant-lies-taste.md
Normal file
5
.changeset/giant-lies-taste.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes prerendering not removing unused dynamic imported chunks
|
|
@ -314,10 +314,12 @@ export class App {
|
|||
}
|
||||
const pathname = this.#getPathnameFromRequest(request);
|
||||
const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
|
||||
const mod = await this.#pipeline.getModuleForRoute(routeData);
|
||||
|
||||
let response;
|
||||
try {
|
||||
// Load route module. We also catch its error here if it fails on initialization
|
||||
const mod = await this.#pipeline.getModuleForRoute(routeData);
|
||||
|
||||
const renderContext = RenderContext.create({
|
||||
pipeline: this.#pipeline,
|
||||
locals,
|
||||
|
|
|
@ -44,8 +44,8 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V
|
|||
for (const pageData of pageDatas) {
|
||||
const resolvedPage = await this.resolve(pageData.moduleSpecifier);
|
||||
if (resolvedPage) {
|
||||
imports.push(`const page = () => import(${JSON.stringify(pageData.moduleSpecifier)});`);
|
||||
exports.push(`export { page }`);
|
||||
imports.push(`import * as _page from ${JSON.stringify(pageData.moduleSpecifier)};`);
|
||||
exports.push(`export const page = () => _page`);
|
||||
|
||||
imports.push(`import { renderers } from "${RENDERERS_MODULE_ID}";`);
|
||||
exports.push(`export { renderers };`);
|
||||
|
|
|
@ -40,7 +40,7 @@ function getNonPrerenderOnlyChunks(bundle: Rollup.OutputBundle, internals: Build
|
|||
const prerenderOnlyEntryChunks = new Set<Rollup.OutputChunk>();
|
||||
const nonPrerenderOnlyEntryChunks = new Set<Rollup.OutputChunk>();
|
||||
for (const chunk of chunks) {
|
||||
if (chunk.type === 'chunk' && (chunk.isEntry || chunk.isDynamicEntry)) {
|
||||
if (chunk.type === 'chunk' && chunk.isEntry) {
|
||||
// See if this entry chunk is prerendered, if so, skip it
|
||||
if (chunk.facadeModuleId?.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
|
||||
const pageDatas = getPagesFromVirtualModulePageName(
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<title>Static Page</title>
|
||||
<title>Static Page should not exist in chunks</title>
|
||||
</head>
|
||||
<body>
|
||||
<Counter client:load />
|
||||
|
|
|
@ -18,4 +18,15 @@ describe('Chunks', () => {
|
|||
const hasImportFromPrerender = !content.includes(`React } from './chunks/prerender`);
|
||||
assert.ok(hasImportFromPrerender);
|
||||
});
|
||||
|
||||
it('does not have prerender code', async () => {
|
||||
const files = await fixture.readdir('/_worker.js/chunks');
|
||||
assert.ok(files.length > 0);
|
||||
for (const file of files) {
|
||||
// Skip astro folder
|
||||
if (file === 'astro') continue
|
||||
const content = await fixture.readFile(`/_worker.js/chunks/${file}`);
|
||||
assert.doesNotMatch(content, /Static Page should not exist in chunks/);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue