Skip to content

Commit

Permalink
changes from ematipico review
Browse files Browse the repository at this point in the history
  • Loading branch information
goulvenclech committed May 2, 2024
1 parent 37ca1ae commit 846dd6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ export function getPagesDatasByComponent(
* Should be removed in the future (in Astro 5 ?).
* Parse internals.pagesByKeys to get the page data with the public key.
* If the page component is unique -> the public key is the component.
* This match the old behavior of the Integrations API, where pages were identified by the component.
* If the page component is shared -> the public key is the internal key.
* This should be the new behavior, since we identify pages by their internal key now.
* Until then, this is not a breaking change, because a shared entrypoint was not supported before.
* @param pagesByKeys A map of all page data by their internal key
*/
export function getPageDatasWithPublicKey(pagesByKeys: Map<string, PageBuildData>): Map<string, PageBuildData> {
Expand Down
19 changes: 9 additions & 10 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,18 @@ async function cleanStaticOutput(
internals: BuildInternals,
ssrOutputChunkNames: string[]
) {
const allStaticFiles = new Set();
const allSSRFiles = new Set();
const prerenderedFiles = new Set();
const onDemandsFiles = new Set();
for (const pageData of internals.pagesByKeys.values()) {
const { moduleSpecifier } = pageData;
const pageBundleId = internals.pageToBundleMap.get(moduleSpecifier);
const entryBundleId = internals.entrySpecifierToBundleMap.get(moduleSpecifier);
if (pageData.route.prerender && !pageData.hasSharedModules && !allSSRFiles.has(pageBundleId ?? entryBundleId)) {
allStaticFiles.add(pageBundleId ?? entryBundleId);
const bundleId = internals.pageToBundleMap.get(moduleSpecifier) ?? internals.entrySpecifierToBundleMap.get(moduleSpecifier);
if (pageData.route.prerender && !pageData.hasSharedModules && !onDemandsFiles.has(bundleId)) {
prerenderedFiles.add(bundleId);
} else {
allSSRFiles.add(pageBundleId ?? entryBundleId);
onDemandsFiles.add(bundleId);
// Check if the component was not previously added to the static build by a statically rendered route
if (allStaticFiles.has(pageBundleId ?? entryBundleId)) {
allStaticFiles.delete(pageBundleId ?? entryBundleId);
if (prerenderedFiles.has(bundleId)) {
prerenderedFiles.delete(bundleId);
}
}
}
Expand All @@ -400,7 +399,7 @@ async function cleanStaticOutput(
// These chunks should only contain prerendering logic, so they are safe to modify.
await Promise.all(
files.map(async (filename) => {
if (!allStaticFiles.has(filename)) {
if (!prerenderedFiles.has(filename)) {
return;
}
const url = new URL(filename, out);
Expand Down

0 comments on commit 846dd6f

Please sign in to comment.