New product features | The latest in technology | The weekly debugging nightmares & more!
July 17, 2023
Take my knowledge and shove it up your brain...
In Next js 13, If you try to use a server action on a page that uses generateStaticParams()
like for example, if you have an e-commerce store, you want the product page to be generated at build time, and you want the users to be able to add the product to the cart using a server action.
If you try to do that, the server action won't work, and if you open the console, you'll see this error:
The reason for that is Post requests aren't supported in SSG
pages.
So how do we fix this...
We don't.
I found that this error occurs in development only.
If you run your project in production (npm run build
then npm start
), You won't get this error and the server action will work as expected.
If you really wanna fix this in development, you can check this pull, apparently enabling preview mode should fix it, but I don't really care, It works fine in production and that's what matters.
Next js 13 group routes is a game changer
This is a new feature in next js 13 that solves so many problems
Metadata guide in Next js 13
Next 13 introduced a new way to optimize your metadata, here's what you need to know
Next js 13 Route handlers explained
Forget the old api routes, this is the way
All you need to know about useOptimistic hook in Next js13
A new experimental feature from Next js 13 that will greatly imporove your UX