Cookies and headers no longer opt-in the entire route for dynamic rendering #49708
Replies: 3 comments 5 replies
-
My experience is that this is actually true regardless of whether or not the server component is nested. No matter what I do, if I use cookies(), then route back to that page, a cached version is served to me for a seemingly arbitrary amount of time until the actual route is refetched by next again. My build output does show all of my routes as being dynamic. I spent all day trying to figure out what I was doing wrong, but I am now suspicious as to whether it’s me or the library… I will try to upload a video with details soon |
Beta Was this translation helpful? Give feedback.
-
related to this issue: But I think the way you said it is clearer. |
Beta Was this translation helpful? Give feedback.
-
So if I understood right, if I'm gonna use cookies, it's better I use it from the server components but not from page or layout? because I need to fetch other data with the auth token from the cookies then every time I use cookies It's just always dynamic and results in super slow loading on my website. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
According to the docs, using
cookies()
orheaders()
opts in the entire route for dynamic rendering: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering#using-dynamic-functionsHowever, the docs for
cookies()
itself mention that this only happens if you use it on the page or layout level: https://nextjs.org/docs/app/api-reference/functions/cookiesThis functionality was recently updated and the first link is no longer correct, if you use
cookies()
in a nested server component, your route stays static.Beta Was this translation helpful? Give feedback.
All reactions