Layout Dynamic with Page Static Content
Answered
Masai Lion posted this in #help-forum
Masai LionOP
If in the main layout file, I use cookies, which basically invalidates the cache for it, does that mean individual pages will also have no cache, or will it be separate?
Answered by joulev
In the future they might support dynamic layout + static page (since it is theoretically implementable), but for now you need fetch()/unstable_cache()
9 Replies
Masai LionOP
I have a layout that reads user cookies for authentication, then individual pages that have complicated operations for static data. Is there any way to make this work?
Masai LionOP
I did some tests and found that if you include
Still have no clue how to solve this, anyone know?
export const dynamic = 'force-static', it will cause the layout to also not get called again, not sure if this is intended behavior. https://codesandbox.io/p/sandbox/exciting-panka-grv467Still have no clue how to solve this, anyone know?
@Masai Lion If in the main layout file, I use cookies, which basically invalidates the cache for it, does that mean individual pages will also have no cache, or will it be separate?
You need to use fetch() or unstable_cache() to opt the page out of dynamic rendering
Since if one part of the whole route is dynamic, the entire route is dynamic
In the future they might support dynamic layout + static page (since it is theoretically implementable), but for now you need fetch()/unstable_cache()
Answer
Masai LionOP
got it, thanks, then is the force-static part a bug or intended?
@Masai Lion I did some tests and found that if you include `export const dynamic = 'force-static'`, it will cause the layout to also not get called again, not sure if this is intended behavior. https://codesandbox.io/p/sandbox/exciting-panka-grv467
Still have no clue how to solve this, anyone know?
Since the “staticity†of a route is determined by all parts of the route, forcing a static page inside a dynamic layout is not allowed and will cause unexpected behaviours like this one. In this case, the full route is forced to be static and in that case cookies() returns an empty store
Masai LionOP
should I report this as a bug?