Allow Client Components access to request headers during SSR #60640
Replies: 4 comments 7 replies
-
Why do you need to fetch this data in the SSR stage? Could you not fetch this data in a parent server component and pass it down? A specific use case example would help this discussion I think. |
Beta Was this translation helpful? Give feedback.
-
@shuding's tweet may be interesting here:
|
Beta Was this translation helpful? Give feedback.
-
Are there no more developments with this? |
Beta Was this translation helpful? Give feedback.
-
i use AsyncLocalStorage in middleware to store headers, then use it in client component, it seems ok. |
Beta Was this translation helpful? Give feedback.
-
Goals
Non-Goals
headers()
functionBackground
Using the pages router you could get access to the incoming request headers in getInitialProps (NextPageContext), allowing you to fetch data and forward the headers properly.
Proposal
Could we get some primitive for this, maybe a
useSSRContext
that's only filled during the SSR prepass?Note
This is already possible today, by calling
headers()
and passing it as props to the client component, although this means the headers are included in the HTML markup which isn't ideal as it exposes http only cookies to be read by JavaScript.Beta Was this translation helpful? Give feedback.
All reactions