Skip to content

Commit

Permalink
Update return shape of generateStaticParams (#40965)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Sep 27, 2022
1 parent e0cc9cd commit 0f41a48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/utils.ts
Expand Up @@ -1126,7 +1126,7 @@ export async function buildAppStaticPaths({
const result = await curGenerate.generateStaticParams({ params })
// TODO: validate the result is valid here or wait for
// buildStaticPaths to validate?
for (const item of result.params) {
for (const item of result) {
newParams.push({ ...params, ...item })
}
}
Expand Down
42 changes: 18 additions & 24 deletions test/e2e/app-dir/app-static/app/blog/[author]/[slug]/page.js
Expand Up @@ -20,34 +20,28 @@ export function generateStaticParams({ params }) {

switch (params.author) {
case 'tim': {
return {
params: [
{
slug: 'first-post',
},
],
}
return [
{
slug: 'first-post',
},
]
}
case 'seb': {
return {
params: [
{
slug: 'second-post',
},
],
}
return [
{
slug: 'second-post',
},
]
}
case 'styfle': {
return {
params: [
{
slug: 'first-post',
},
{
slug: 'second-post',
},
],
}
return [
{
slug: 'first-post',
},
{
slug: 'second-post',
},
]
}
default: {
throw new Error(`unexpected author param received ${params.author}`)
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/app-dir/app-static/app/blog/[author]/layout.js
Expand Up @@ -10,7 +10,5 @@ export default function Layout({ children, params }) {
export function generateStaticParams({ params }) {
console.log('/blog/[author] generateStaticParams', JSON.stringify(params))

return {
params: [{ author: 'tim' }, { author: 'seb' }, { author: 'styfle' }],
}
return [{ author: 'tim' }, { author: 'seb' }, { author: 'styfle' }]
}

0 comments on commit 0f41a48

Please sign in to comment.