From b3ccdfb12c43d53d813125f19786cac652b2eec4 Mon Sep 17 00:00:00 2001 From: Goulven Clec'h Date: Thu, 25 Apr 2024 14:02:28 +0200 Subject: [PATCH] fix?: ssr clean static output --- packages/astro/src/core/build/generate.ts | 4 ++-- packages/astro/src/core/build/static-build.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 48a9d84bed..143bc6316c 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -47,7 +47,7 @@ import { createRequest } from '../request.js'; import { matchRoute } from '../routing/match.js'; import { getOutputFilename } from '../util.js'; import { getOutDirWithinCwd, getOutFile, getOutFolder } from './common.js'; -import { cssOrder, getPageDataByComponent, mergeInlineCss } from './internal.js'; +import { cssOrder, getPageData, mergeInlineCss } from './internal.js'; import { BuildPipeline } from './pipeline.js'; import type { PageBuildData, @@ -257,7 +257,7 @@ async function generatePage( const { config, internals, logger } = pipeline; const pageModulePromise = ssrEntry.page; // TODO: Why do we need to get PageData from PageData? - const pageInfo = getPageDataByComponent(internals, pageData.route.component); + const pageInfo = getPageData(internals, pageData.route.component, pageData.route.route); // Calculate information of the page, like scripts, links and styles const styles = pageData.styles diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index a3ec4925be..50baa44e79 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -370,11 +370,17 @@ async function cleanStaticOutput( ) { const allStaticFiles = new Set(); for (const pageData of internals.pagesByKeys.values()) { - if (pageData.route.prerender && !pageData.hasSharedModules) { - const { moduleSpecifier } = pageData; - const pageBundleId = internals.pageToBundleMap.get(moduleSpecifier); - const entryBundleId = internals.entrySpecifierToBundleMap.get(moduleSpecifier); + console.log("[cleanStaticOutput] pageData: ", pageData.key, "— is prerender ? ", pageData.route.prerender); + const { moduleSpecifier } = pageData; + const pageBundleId = internals.pageToBundleMap.get(moduleSpecifier); + const entryBundleId = internals.entrySpecifierToBundleMap.get(moduleSpecifier); + if (pageData.route.prerender && !pageData.hasSharedModules && allStaticFiles.has(pageBundleId ?? entryBundleId)) { allStaticFiles.add(pageBundleId ?? entryBundleId); + } else { + // Check if the page pageBundleId or entryBundleId is already in the set, if so, remove it + if (allStaticFiles.has(pageBundleId ?? entryBundleId)) { + allStaticFiles.delete(pageBundleId ?? entryBundleId); + } } } const ssr = isServerLikeOutput(opts.settings.config);