summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Caleb Jasik <calebjasik@jasik.xyz> 2021-10-12 12:04:22 -0500
committerGravatar GitHub <noreply@github.com> 2021-10-12 13:04:22 -0400
commit6813106a5d5206be2c7aec1b6d696c825b5b069c (patch)
treee4cc7caf83549bbe469bd107787ecc038eb63316
parentab990b220472fb50074985059513528c72cb4c29 (diff)
downloadastro-6813106a5d5206be2c7aec1b6d696c825b5b069c.tar.gz
astro-6813106a5d5206be2c7aec1b6d696c825b5b069c.tar.zst
astro-6813106a5d5206be2c7aec1b6d696c825b5b069c.zip
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
-rw-r--r--.changeset/gold-deers-cry.md5
-rw-r--r--packages/astro/src/runtime.ts6
2 files changed, 8 insertions, 3 deletions
diff --git a/.changeset/gold-deers-cry.md b/.changeset/gold-deers-cry.md
new file mode 100644
index 000000000..d0f92c9de
--- /dev/null
+++ b/.changeset/gold-deers-cry.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Improve getStaticPaths memoization to successfully store values in the cache
diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts
index c10a3bce4..83fccfb90 100644
--- a/packages/astro/src/runtime.ts
+++ b/packages/astro/src/runtime.ts
@@ -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 */