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.
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 client components 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With