Need help understanding SSG
Answered
Argentine hake posted this in #help-forum
Argentine hakeOP
A newbie here: How does next13 SSG work for server components that require user cookies or headers when fetching data from an API? Or is this an invalid use case? I can see how it makes sense for statically generated pages/components to never use cookies and headers; simply because it happens at build time. But does that also mean every server component that fetches data needs to have force-dynamic turned on, because by default every server component is static? 😕 I’ve been getting DynamicServerError during build time and I m wondering what’s causing it.
Another question is, does on demand revalidatePath evict the cache on Vercel’s edge CDN?
Another question is, does on demand revalidatePath evict the cache on Vercel’s edge CDN?
Answered by aardani
But does that also mean every server component that fetches data needs to have force-dynamic turned on, because by default every server component is static?No, it does not have to.
force-dynamic is only required if you want the data to be refetched at every request time, turning it into dynamically computed route.Fetches can still be done at build time
3 Replies
You can't use user cookies or headers INSIDE SSG routes but you can still use middleware to run for those SSG routes.
In the case of using cookies or headers in server-rendered components, you can opt-into dynamically rendered routes at request time, a.k.a SSR.
In the case of using cookies or headers in server-rendered components, you can opt-into dynamically rendered routes at request time, a.k.a SSR.
But does that also mean every server component that fetches data needs to have force-dynamic turned on, because by default every server component is static?No, it does not have to.
force-dynamic is only required if you want the data to be refetched at every request time, turning it into dynamically computed route.Fetches can still be done at build time
Answer
Argentine hakeOP
@aardani thank you!