Client Components Rendering on Client Side or Server Side #54114
Replies: 3 comments 12 replies
-
Client components are rendered during any form of SSR, not just during pre-rendering.
This document is pretty good at eliminating any doubts: Maybe the "primarily", word is not the best choice there, but I do believe it is there to show "contrast" to React Server's components, all-in behavior.
So the wording indicates how Client components are, mainly designed to achieve a set of features that give interactivity to a page, but are also designed to be part of the SSR output tree. The primary goal you'd have when using a Client Component is to gain interactivity. |
Beta Was this translation helpful? Give feedback.
-
Thanks for clear explanation. There are still few questions requiring clarification:
|
Beta Was this translation helpful? Give feedback.
-
hey , In Nextjs Docs (Page: Lazy Loading > Skipping SSR) "Client Components will be pre-rendered (SSR) by default." i am also confused here? is this current?? if not plz clarify it. when Nextjs Docs say "Client Components will be pre-rendered (SSR) by default" does that mean React Client component JavaScript get's render on the Server???? and server send pre-render React Client component JavaScript file?? i use to think that only the React Server Component gets render on the server and server send pre-render RSC Payload??? i am confused?? |
Beta Was this translation helpful? Give feedback.
-
I am confused by how docs describe client components. It states client components are pre-rendered on the server and hydrated on the client, but it also says components in the Client Component module graph are primarily rendered on the client.
My questions is that in which context client components will be pre-rendered on the server and in which context it will be rendered on client. Please kindly clarify.
The official docs say:
Client Components
Client Components enable you to add client-side interactivity to your application. In Next.js, they are pre-rendered on the server and hydrated on the client. You can think of Client Components as how components in the Pages Router have always worked.
Good to know:
Components in the Server Component module graph are guaranteed to be only rendered on the server.
Components in the Client Component module graph are primarily rendered on the client, but with Next.js, they can also be pre-rendered on the server and hydrated on the client.
The "use client" directive must be defined at the top of a file before any imports.
"use client" does not need to be defined in every file. The Client module boundary only needs to be defined once, at the "entry point", for all modules imported into it to be considered a Client Component.
Link: https://nextjs.org/docs/getting-started/react-essentials#client-components
Beta Was this translation helpful? Give feedback.
All reactions