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
Sloth bearOP
Potential use-case: Best selling products in a system where product data can change often at times.
Is it possible to use
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
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
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams
6 Replies
@Sloth bear 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?
<@138831444461092866> I saw your answer to another question about `generateStaticParams` so I hope you don't mind me pinging you here 🙂
That’s almost what happens when you use dynamicParams = true (default)
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams
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
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
wouldn't one?
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 bear 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?
yes that's correct. it's static after all, there are things you need to do to revalidate a static page
Sloth bearOP
Absolutely, thanks for the input, also to you @chisto, I saw you replied 🙂
you're welcome