From 6813106a5d5206be2c7aec1b6d696c825b5b069c Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Tue, 12 Oct 2021 12:04:22 -0500 Subject: [PATCH] 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 --- .changeset/gold-deers-cry.md | 5 +++++ packages/astro/src/runtime.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/gold-deers-cry.md 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 }; + cache: { staticPaths: Record> }; 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 { - 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 */