Why is importing a Server Component into a Client Component still working? #76150
-
|
According to the Next.js documentation:
However, when I tested this in my project, the import still works, and no errors occur. My github link > https://github.com/developer-choi/reproduce-2025-02-18 Below is my reasoning process for why this might be happening. Rule 1: Components imported into a "use client" component are considered Client Components.
Based on this, it seems that the Rule 2: In the App Router, components are Server Components by default.
Conclusion:It looks like I misunderstood the interaction between these two rules. That said, I still need an example that clearly demonstrates the statement:
Could someone guide me on how to modify my codes to properly illustrate this restriction? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
The component you have called Server Component, can still be opted in to a client module, because it doesn't do anything, that would prevent that. You could for example:
|
Beta Was this translation helpful? Give feedback.
The component you have called Server Component, can still be opted in to a client module, because it doesn't do anything, that would prevent that.
You could for example:
async, and then add some state in your client component, try changing that state, and you'll most likely see an error (you have a counter)fs, or some other Node.js API.import 'server-only', note that you'd need to install this package