Why Do I See Pre-Rendered HTML in Source Code When Using 'use client' in Next.js? #67916
-
|
I'm working on a Next.js application and have some confusion regarding pre-rendering and client-side rendering. I've been using the 'use client' directive at the top of my components to ensure they are rendered on the client side. However, when I inspect the source code in my browser, I see a lot of pre-rendered HTML. Here is an example of what I see: My understanding was that with 'use client', the components would only render on the client side, so I didn't expect to see so much pre-rendered content in the initial HTML. Could someone please explain why this is happening? How does Next.js handle pre-rendering and client-side rendering in this context? Does using 'use client' still involve some form of server-side pre-rendering, and if so, what are the benefits? Thanks in advance for your insights! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
That's wrong. Many tech-influencers, have heavily miscommunicated this. Client Components, are the traditional components, so to speak, and these are rendered during any type of SSR pass. The special behavior, rather, is for Server Components, which do not send their JavaScript to the client. If want to defer rendering to the client, there are other techniques such as:
That they get rendered is also important, for other matters, see for example: #67878 (comment) |
Beta Was this translation helpful? Give feedback.
That's wrong. Many tech-influencers, have heavily miscommunicated this.
Client Components, are the traditional components, so to speak, and these are rendered during any type of SSR pass.
The special behavior, rather, is for Server Components, which do not send their JavaScript to the client.
If want to defer rendering to the client, there are other techniques such as: