Next.js Discord

Discord Forum

Does a hybrid SSG approach exist that falls back first to SSR, and then to a 404 page?

Answered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
Potential use-case: Best selling products in a system where product data can change often at times.

Is it possible to use generateStaticParams for a subset of products whose product pages then get rendered using SSG. If the ID param is not returned by generateStaticParams the server should fall back to SSR and if the product cannot be found route to a 404 page.

Is this possible and/or viable? Or should pages like that simply use SSR and that's it?

@chisto I saw your answer to another question about generateStaticParams so I hope you don't mind me pinging you here 🙂
Answered by joulev
That’s almost what happens when you use dynamicParams = true (default)

https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams
View full answer

6 Replies

Answer
Almost, because for params not returned by generateStaticParams, dynamic rendering only happens for the first render, it will be cached and SSG’d thereafter
Sloth bearOP
Thanks for getting back to me this quickly guys!

Combining both generateStaticParams and dynamicParams would be ISR then?

https://nextjs.org/docs/app/guides/incremental-static-regeneration

This means that after updating a product one would either have to

- wait for the cache to be invalidated or
- call revalidatePath for the specific path, e.g. products/1

wouldn't one?
Sloth bearOP
Absolutely, thanks for the input, also to you @chisto, I saw you replied 🙂
you're welcome