Are children of a layout forced to be dynamic if a layout accesses headers/cookies
Answered
Wesley Janse posted this in #help-forum
Question, I'm working on an eccomerce site and might have noticed an issue with the static rendering. We have a root layout that access some cookies/headers for the session. Does this mean that all content on the site is dynamic? or is next smart enough to handle the layout dynamically while the rest is static?
Answered by Sun bear
No, if you make your layout dynamic, the whole page is dynamic. You can cache the content of the page and with PPR render the satic content immediatly.
8 Replies
the layout is Independent from the page.tsx
So the layout can be dynamic when the pages inside are static?
Sun bear
No, if you make your layout dynamic, the whole page is dynamic. You can cache the content of the page and with PPR render the satic content immediatly.
Answer
@Wesley Janse solved?
PPR/Suspense is recommended here, plus either "use cache" or unstable_cache to manually cache the content that is not dependent on headers/cookies
I thought it would be like when you handling client components and use children as server components. Like that you can use serverside stuff, that are children of client components. But in this case it looks like its different, because it's the layout 🤔
it determines at build time that the whole route cannot be statically generated at build time alone. so it never bothers with building the page component itself. the page component is now dynamic by default, though slapping
"use cache"
on it will probably just work (requiring dynamicIO)