CodePark/ questions / Server & Client Components
START PRACTICINGPRACTICE
Frontend question · Next.js › Server & Client Components

Do Client Components run on the server? Describe what happens on the first load versus a client-side navigation.

Yes. "Client" means the component also sends JavaScript to the browser. It does not mean it runs only there.

First load:

  • Next.js renders Server Components into the RSC payload. This is a compact description of the rendered Server Component tree.
  • It uses that payload plus the Client Components to prerender HTML. So the user sees content before any JavaScript runs.
  • In the browser, React uses the payload to rebuild and match the tree.
  • React then hydrates the Client Components: it attaches event handlers and state to the HTML already on the screen.

Later client-side navigations:

  • The server sends no new HTML.
  • The browser fetches only the RSC payload for the new route.
  • Client Components render entirely in the browser.

This is why a Client Component that touches window during render can still break. On the first load it runs on the server too, where window does not exist.

  • Client Components are also prerendered to HTML on the server.
  • The RSC payload is a compact description of the Server Component output.
  • Hydration attaches event handlers and state in the browser.
  • Later navigations fetch only the RSC payload, not new HTML.