Fix getStaticPaths
regressions with nested arrays (#5375)
* Fix getStaticPaths regression * Add changeset * Add test
This commit is contained in:
parent
591153f457
commit
f9104354b8
4 changed files with 23 additions and 1 deletions
5
.changeset/angry-dragons-drive.md
Normal file
5
.changeset/angry-dragons-drive.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix regression causing nested arrays in `getStaticPaths`'s return value to throw an error
|
|
@ -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>();
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
8
packages/astro/test/fixtures/astro-get-static-paths/src/pages/nested-arrays/[slug].astro
vendored
Normal file
8
packages/astro/test/fixtures/astro-get-static-paths/src/pages/nested-arrays/[slug].astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
export function getStaticPaths() {
|
||||
return [
|
||||
[ { params: {slug: "slug1"} } ],
|
||||
[ { params: {slug: "slug2"} } ],
|
||||
]
|
||||
}
|
||||
---
|
Loading…
Reference in a new issue