summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/angry-dragons-drive.md5
-rw-r--r--packages/astro/src/core/render/route-cache.ts6
-rw-r--r--packages/astro/test/astro-get-static-paths.test.js5
-rw-r--r--packages/astro/test/fixtures/astro-get-static-paths/src/pages/nested-arrays/[slug].astro8
4 files changed, 23 insertions, 1 deletions
diff --git a/.changeset/angry-dragons-drive.md b/.changeset/angry-dragons-drive.md
new file mode 100644
index 000000000..a33dba38f
--- /dev/null
+++ b/.changeset/angry-dragons-drive.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix regression causing nested arrays in `getStaticPaths`'s return value to throw an error
diff --git a/packages/astro/src/core/render/route-cache.ts b/packages/astro/src/core/render/route-cache.ts
index 26cf4f6fe..35cbaab3e 100644
--- a/packages/astro/src/core/render/route-cache.ts
+++ b/packages/astro/src/core/render/route-cache.ts
@@ -49,11 +49,15 @@ export async function callGetStaticPaths({
},
});
+ // Flatten the array before validating the content, otherwise users using `.map` will run into errors
+ if (Array.isArray(staticPaths)) {
+ staticPaths = staticPaths.flat();
+ }
+
if (isValidate) {
validateGetStaticPathsResult(staticPaths, logging, route);
}
- staticPaths = staticPaths.flat();
const keyedStaticPaths = staticPaths as GetStaticPathsResultKeyed;
keyedStaticPaths.keyed = new Map<string, GetStaticPathsItem>();
diff --git a/packages/astro/test/astro-get-static-paths.test.js b/packages/astro/test/astro-get-static-paths.test.js
index 80b81140a..3211f3318 100644
--- a/packages/astro/test/astro-get-static-paths.test.js
+++ b/packages/astro/test/astro-get-static-paths.test.js
@@ -101,6 +101,11 @@ describe('getStaticPaths - route params type validation', () => {
await devServer.stop();
});
+ it('resolves 200 on nested array parameters', async () => {
+ const res = await fixture.fetch('/nested-arrays/slug1');
+ expect(res.status).to.equal(200);
+ });
+
it('resolves 200 on matching static path - string params', async () => {
// route provided with { params: { year: "2022", slug: "post-2" }}
const res = await fixture.fetch('/blog/2022/post-1');
diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/nested-arrays/[slug].astro b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/nested-arrays/[slug].astro
new file mode 100644
index 000000000..9bd7b4f41
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/nested-arrays/[slug].astro
@@ -0,0 +1,8 @@
+---
+ export function getStaticPaths() {
+ return [
+ [ { params: {slug: "slug1"} } ],
+ [ { params: {slug: "slug2"} } ],
+ ]
+ }
+---