Skip to content

Commit

Permalink
Keep track of paths that have already been built
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jul 26, 2022
1 parent 9b4fde2 commit 3d865dc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ export async function generatePages(
const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir;
const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder);
const ssrEntry = await import(ssrEntryURL.toString());
const builtPaths = new Set<string>;

for (const pageData of eachPageData(internals)) {
await generatePage(opts, internals, pageData, ssrEntry);
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
}
info(opts.logging, null, dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`));
}
Expand All @@ -115,6 +116,7 @@ async function generatePage(
internals: BuildInternals,
pageData: PageBuildData,
ssrEntry: SingleFileBuiltModule,
builtPaths: Set<string>,
) {
let timeStart = performance.now();
const renderers = ssrEntry.renderers;
Expand Down Expand Up @@ -149,7 +151,7 @@ async function generatePage(
info(opts.logging, null, `${icon} ${pageData.route.component}`);

// Get paths for the route, calling getStaticPaths if needed.
const paths = await getPathsForRoute(pageData, pageModule, opts);
const paths = await getPathsForRoute(pageData, pageModule, opts, builtPaths);

for (let i = 0; i < paths.length; i++) {
const path = paths[i];
Expand All @@ -167,12 +169,13 @@ async function getPathsForRoute(
pageData: PageBuildData,
mod: ComponentInstance,
opts: StaticBuildOptions,
builtPaths: Set<string>,
): Promise<Array<string>> {
let paths: Array<string> = [];
if(pageData.route.pathname) {
paths.push(pageData.route.pathname);
builtPaths.add(pageData.route.pathname);
} else {
const builtPaths = new Set<string>();
const route = pageData.route;
const result = await callGetStaticPaths({
mod,
Expand Down Expand Up @@ -220,6 +223,11 @@ async function getPathsForRoute(
const matchedRoute = matchRoute(staticPath, opts.manifest);
return matchedRoute === route;
});

// Add each path to the builtPaths set, to avoid building it again later.
for(const staticPath of paths) {
builtPaths.add(removeTrailingForwardSlash(staticPath));
}
}

return paths;
Expand Down

0 comments on commit 3d865dc

Please sign in to comment.