I comprehend that server components undergo complete rendering on the server, and they aren't included in the JS bundle transmitted to the client. Additionally, server components don't undergo hydration on the client side.
However, my uncertainty lies with client components.
- Are client components entirely incorporated into the client JS bundle and exclusively handled on the client side? —similar to conventional React behavior?
- Alternatively, are client components partially rendered on the server and then dispatched to the client side with their JS bundle, undergoing hydration? This behavior is somewhat reminiscent of the pages router in Next.
I acknowledge the possibility that the handling of client components may differ from one framework to another, and Next.js might handle them distinctively compared to frameworks like Gatsby. I would appreciate clarification, particularly in the context of the Next app router.
I was going through this blog by Josh W. Comeau where it was mentioned that client components are rendered both on the client side and server side:
Excerpt from Josh W, Comeau blog
But I don't seem to find any other tutorial or blog (as far as I have searched) that seem to acknowledge the the above. The underline tone is always that the client components are handled client side.
This is causing confusion on how client components handled? 100% client side or both client and server side? If it is legit partially client and server then how exactly does it happen in context of Next App router?
For nextjs your
clientcomponents are also rendered statically on the server for fast initial load times. It is then hydrated to add interactivity to those components. For your questions this means:No, client components are initially rendered on the server to send over in the static HTML to present it to the user
Yes, client components are being hydrated using the hydrateRoot
As from the documentation:
On the server:
Then, on the client:
Read more on the nextjs documentation on rendering, especially this part