Downstream imports of cookies()
do not make a page dynamic
#75146
Unanswered
SolidAnonDev
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all.
I'm interested in discussing or finding some answers to why imports of
cookies()
does not result in anasync
page in the app router becoming dynamic if it's imported in files other than the page in question, but still called for from that page. Unless I am doing something wrong, I am still required to useexport const dynamic = 'force-dynamic'
in my page in order to have it be dynamic, or the cookie I am calling for will returnundefined
, as that's what the value may have been when the application was built. All this despite the fact thatcookies
is imported, but just not directly in the page itself.It does not appear that this behavior holds true when it comes to
layout.tsx
pages. These files do not require any specific dynamic marking, and will updating accordingly as the cookies change.I may be going about this entirely wrong and would like to know if so.
This only happens in production, not in development. It wasn't until I deployed my app that I became aware of this.
The general code in question would look something like the below. I have greatly reduced what I am actually doing to this, and there are reasons that the functionality exists across multiple files that isn't relevant here:
and
getMyCookieValue
located in a different file:and finally
getThisCookieValue
in yet another file:As you can see, there is a
cookies()
import, but it happens a few files over. So I'm not sure why this still wouldn't result in the page becoming dynamic.Any help on this would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions