Add value to staticPaths cache before we await it (#1498)

* Add value to staticPaths cache before we await it

Fixes https://github.com/snowpackjs/astro/issues/1454

* Update `cache.staticPaths` to store Promises rather than immediate values
This commit is contained in:
Caleb Jasik 2021-10-12 12:04:22 -05:00 committed by GitHub
parent ab990b2204
commit 6813106a5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Improve getStaticPaths memoization to successfully store values in the cache

View file

@ -31,7 +31,7 @@ const { CompileError } = parser;
export interface AstroRuntimeConfig {
astroConfig: AstroConfig;
cache: { staticPaths: Record<string, GetStaticPathsResult> };
cache: { staticPaths: Record<string, Promise<GetStaticPathsResult>> };
logging: LogOptions;
mode: RuntimeMode;
snowpack: SnowpackDevServer;
@ -81,8 +81,8 @@ function getParams(array: string[]) {
}
async function getStaticPathsMemoized(runtimeConfig: AstroRuntimeConfig, component: string, mod: any, args: GetStaticPathsArgs): Promise<GetStaticPathsResult> {
runtimeConfig.cache.staticPaths[component] = runtimeConfig.cache.staticPaths[component] || (await mod.exports.getStaticPaths(args)).flat();
return runtimeConfig.cache.staticPaths[component];
runtimeConfig.cache.staticPaths[component] = runtimeConfig.cache.staticPaths[component] || mod.exports.getStaticPaths(args);
return (await runtimeConfig.cache.staticPaths[component]).flat();
}
/** Pass a URL to Astro to resolve and build */