-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Importing of use state and lifecycle effects in Next.js server component #11167
Comments
I've contacted the React team on this, let's see what the result will be. |
@phryneas It's working for me but also breaking other external non-rsc components in my project. |
I don't think the |
Can you give an example of a component that would break? In a non-rsc case, the compiler should pick up the normal
Because "use client" works on a per-file basis, not on a per-component basis. Depending on which build of Apollo Client you use in the end, you might even be dealing with just "one file" for the full Apollo Client. You could not import anything from AC anymore. |
I think it's because of another external React library that caused the problem. After fixing everything works just fine now.
Ok, I got your point. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
As of now, Next.js (
v13.4.19
) is trying to resolve React components under@apollo/client/react
which contains use state and lifecycle effects that are not supported in RSC.Without using
"use client"
directive on top of the component that contains use state and lifecycle effects, I think Next.js assumes that those components can be used in RSC. Previously PR (#11000) prevented the errors. But in the end, It did not fix how Next.js is going to treat those components.The error appears when using Next.js edge runtime and importing
@apollo/client
in the underlying code that is related to one of the RSC components. But the error doesn't appear when using Node.js runtime or when using edge runtime with turbopack, I think that somehow this problem is related to the Next.js compiler config between webpack and turbopack.Workaround
I came up with 2 workarounds. The first one is directly importing the core function directly
@apollo/client/core
. This will prevent the compiler from bundling the unsupported hooks into the server component. Another workaround is to patch the package by adding"use client"
directive to every component that has use state and lifecycle effect.Related: #10974
Link to Reproduction
https://codesandbox.io/p/sandbox/white-microservice-h9xd4f
Reproduction Steps
No response
The text was updated successfully, but these errors were encountered: