Inconsistent behavior of generateStaticParams #84925
Replies: 1 comment 3 replies
-
This difference occurs because When you return In other words, It would definitely help if the docs clarified that an empty object changes the route generation mode, not just the pre-rendered params. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I had this bug registered that I think was closed too early: #84801
For any good framework or library consistency in behavior is crucial long term. If I as a user needs to think about some features having different effects in different circumstances it will be hard to know when to do what over time.
In the specific bug and in the reproduction I have created I noticed a difference in behavior when I used
generateStaticParams
.First let's explain how I, and probably a lot of other developers see
generateStaticParams
. The function is there to generate an array of values representing the params for the pages you want to prerender. In other words, all the values not present in the array will not be prerendered. This is perfectly fine, but what I find strange is take a path likeproduct/[id]
and try to go toproduct/2
it behaves differently if you havegenerateStaticParams = () => [{}]
andgenerateStaticParams = () => [{id:"1"}]
.Note that in both cases I do NOT include the id "2". So in other words I tell nextjs that
product/2
should not be prerendered in both scenarios and therefor in both scenarios I expect the pageproduct/2
to be treated the same if I havegenerateStaticParams = () => [{}]
andgenerateStaticParams = () => [{id:"1"}]
, which is not the case.To see the difference in action you can visit these two pages:
https://next16-demo-git-static-params-bug-mastojs-projects.vercel.app/wat/anyslug
https://next16-demo-git-static-params-bug-mastojs-projects.vercel.app/anyslug
Both are identical except for the
generateStaticParams
. Code for the repro is here: https://github.com/mastoj/next16-demo/tree/static-params-bugBeta Was this translation helpful? Give feedback.
All reactions