-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not import and use Tab component within React Server Component on Next.js 13 #2021
Comments
Most of our components rely on React Context and browser-specific APIs. React Server Components (RSCs) do not support context. This is because they're meant to run and communicate with server backends, perform sensitive tasks, fetching data asynchronously on the server, and eliminating unused client-side JS that only matters for an initial render, data fetching, or other backend-only tasks. However, neither using Context nor any browser-specific APIs qualifies as this. No matter what you still need to ship Headless UI to the browser to be able to interact with the components. Now, we do support SSR in some limited capacity for some components but SSR itself is orthogonal to RSCs. When using them you get some SSR plus additional capabilities but you also have more restrictions on what you can and cannot do and use. This is why, as of 1.7.4, Unfortunately, the only thing that using Bit of a lengthy explanation but I hope that explains how things work and why you can't just import them directly. I wish you could that would make things so much easier. 🤷 |
@thecrypticace Thank you for replying. When Vercel introduced the different between RSC and Client components, they said |
In context of #2021 (comment):
Thank you for the detailed reply, @thecrypticace! It seems that things have been changed and libraries are expected to use
Adding |
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.7.4
What browser are you using?
Safari
Reproduction URL
https://github.com/judewang/headlessui-rsc
With commands to start dev server:
Describe your issue
I've read #1981 and thought we could import components from headlessui and use it right in the server component, but it failed to compile.
I've tried some approaches to use Tab component as sample code within server component, like wrapping the exporting within a client component:
And it still failed.
Then I found 2 ways to make it work, one is wrapping all of the component that using Tab component as a big client component:
This approach can result to a big client component since it's hard to pass several server components through the client component's props, this makes all child components within this big client component become client components, too.
The other way is re-exporting Tab components individually and using it right in the Server Component:
In my opinion, the second way may has better performance but the usage is different than described in documentation. Not sure is this need to be noticed in the usage section of the documentation or should the exporting structure need some revise?
The text was updated successfully, but these errors were encountered: