Skip to content

Server Components vs Client Components in Next.js: what runs where

Guide/ 14 min read

The mental model behind Next.js Server and Client Components: a server tree with client leaves, server components passed as children, and what reaches the browser.

  • React
  • Next.js
  • Performance
In this article (9)
  1. Next.js renders Server Components by default
  2. What a Server Component can do
  3. When you need 'use client'
  4. Push interactivity down to the leaves
  5. Pass Server Components as children (or any prop)
  6. What reaches the browser: HTML, RSC Payload and JavaScript
  7. Common mistakes
  8. Frequently asked questions
  9. Checklist

In the Next.js App Router, components are Server Components by default: they run on the server, can read data, and their code never reaches the browser. Client Components are the interactive leaves of the tree. The browser only gets the HTML, the serialized output of the Server Components, and the JavaScript for those leaves.

We already covered where to put 'use client' and how much JavaScript you save by moving it down. This is the mental model behind it: the component tree, who owns what, and what gets serialized. Everything shown here came from a local demo on Next.js 15.5.23 with React 19, including the real payload the server returned. The demo store is in Spanish, so its UI strings are too.

Next.js renders Server Components by default

The Next.js Server and Client Components guide says it in its first line: layouts and pages are Server Components by default. There is no directive to mark them. The React reference clears up a common mix-up: 'use server' does not mark Server Components. It marks Server Functions, which are something else.

A Server Component renders before anything reaches the browser, in a separate environment: once at build time or on every request. Its code is not sent to the client. What gets sent is its result, already computed.

Think of your page as a tree. The root (the layout) and most of the branches are server. The client shows up only where something has to respond to the user: a size picker, a set of tabs, a search box. Those are the leaves. This is the product page from our demo:

the tree of a product pageserverclientlayout.tsxpage.tsx · asynch1 · priceAddToCartTabsReviews · asyncowner: pageparent: Tabsserver by default, client at the leavesReviews runs on the server even though Tabs shows it

Scroll the figure sideways to see all of it

layout.tsx, page.tsx, the title, the price and Reviews run on the server. AddToCart and Tabs are client. Look at Reviews: it shows up inside Tabs, yet it is not a client component. You will see why below.

One point from the Next.js guide to the server and client boundary prevents a lot of confusion: a Client Component also renders on the server. Next.js turns it into HTML for the first load, and then the browser hydrates it. The real difference is elsewhere: a Server Component's code never reaches the browser; a Client Component's code does.

What a Server Component can do

Because it only runs on the server, a Server Component can do things a browser component cannot:

  • Be async and await data while rendering. React calls these async components: you write await getProduct(id) inside the component, with no API route in between.
  • Read the database, files or secrets. None of it reaches the client, as long as you do not pass it as a prop (more on that with costCents).
  • Use heavy libraries without shipping them. React's example renders Markdown with marked and sanitize-html: in a client component both land in the bundle; in a server component, neither does.
  • Put content in the first HTML. The text is in the response, with no wait for JavaScript.

What it cannot do is anything that depends on the browser or on time passing: useState, useEffect, handlers like onClick, React context, and APIs like window. Its code does not exist in the browser, so it has no way to react to a click.

Note that not every bit of interactivity needs your own JavaScript. The Next.js guide lists three examples that work in a Server Component: <details> opens and closes on its own, a <form> can submit to a Server Function through its action prop, and <video controls> plays without help. Before you write a client component, check whether HTML already does the job.

When you need 'use client'

The Next.js guide gives four reasons for a Client Component: state and event handlers, lifecycle effects, browser-only APIs, and custom hooks that use any of those. Add a fifth: a context provider, because context does not work in Server Components. If the component does none of these, keep it on the server.

If the component…It goes on theWhy
Reads the database or uses a secretServerThe code and the secret never leave the server
Uses a heavy library just to render (Markdown, dates, syntax highlighting)ServerThe library stays out of the bundle
Only displays data: title, price, description, reviewsServerThere is nothing to hydrate
Opens and closes with <details> or submits a formServerThe browser already provides that behavior
Uses useState or onClickClientIt needs code that responds in the browser
Uses useEffectClientEffects only run in the browser
Reads window or localStorageClientThose APIs do not exist on the server
Provides a context (provider)Client, wrapping childrenContext does not exist in Server Components

With useEffect, ask one question first: do you need it at all? Plenty of components turn client just for an effect that copies props into state; see why useEffect is the wrong tool for derived state. And if the effect fetches data on mount, that data should almost always be read by a Server Component instead.

server or client? decide by what it doesif the component…goes on thereads the database or a secretserveruses a heavy library to renderserveronly shows data: price, textserveropens and closes with <details>server (native HTML)uses useState or onClickclientuses useEffectclientreads window or localStorageclientprovides a context (provider)client, wraps childrenif none of these apply, keep it on the servercriteria from the Next.js guide and the React reference

Scroll the figure sideways to see all of it

Push interactivity down to the leaves

The rule for the shape of the tree: root and branches on the server, client at the leaves. This is the demo page, an async Server Component:

import { notFound } from "next/navigation";
import { getProduct } from "@/lib/products";
import AddToCart from "./add-to-cart";
import Tabs from "./tabs";
import Reviews from "./reviews";

export default async function Page({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const product = await getProduct(id);
  if (!product) notFound();

  const price = new Intl.NumberFormat("es-MX", { style: "currency", currency: "MXN" })
    .format(product.priceCents / 100);

  return (
    <main>
      <h1>{product.name}</h1>
      <p>{price}</p>
      <AddToCart productId={product.id} sizes={product.sizes} />
      <Tabs
        panels={[
          { label: "Reseñas", content: <Reviews productId={product.id} /> },
          { label: "Envío", content: <p>Envío gratis desde $999.</p> },
        ]}
      />
    </main>
  );
}
  1. No directive: it is a Server Component by default, which is why it can be async.
  2. getProduct comes from lib/products.ts, which starts with import "server-only". If a client file ever imported it, the build would fail.
  3. await params: in Next.js 15 the route params arrive as a promise.
  4. The price is formatted here. The browser gets the string $1,899.00, not Intl or the cents.
  5. AddToCart gets only what it uses: an id and an array of sizes. It does not get the whole product, and that matters (see below).
  6. Tabs gets an array of panels; each content is JSX rendered by this page.

The client leaf is small:

"use client";

import { useState } from "react";

export default function AddToCart({ productId, sizes }: { productId: string; sizes: string[] }) {
  const [size, setSize] = useState(sizes[0]);
  const [added, setAdded] = useState(false);

  return (
    <div>
      {sizes.map((s) => (
        <button key={s} aria-pressed={s === size} onClick={() => setSize(s)}>
          {s}
        </button>
      ))}
      <button onClick={() => setAdded(true)} data-product={productId}>
        {added ? `Agregado: talla ${size}` : "Agregar al carrito"}
      </button>
    </div>
  );
}
  1. "use client" on the first line: this file is the entry point into the client graph.
  2. Two pieces of state: the chosen size and whether it was added.
  3. Each size is a button with aria-pressed, so a screen reader announces which one is active.
  4. The last button changes its label on click. In the demo, Playwright picked size 27, clicked, and read "Agregado: talla 27".

If the page needs a search box tomorrow, it goes in another leaf. What you should not do is move the whole page to the client; we measured what that costs in the 'use client' article.

Pass Server Components as children (or any prop)

This is the part that trips people up. Tabs is a client component because it switches tabs with useState. But it shows Reviews, which is async and reads data. How can a client component display a server one?

"use client";

import { useState, type ReactNode } from "react";

export default function Tabs({ panels }: { panels: { label: string; content: ReactNode }[] }) {
  const [active, setActive] = useState(0);

  return (
    <section>
      {panels.map((p, i) => (
        <button key={p.label} aria-pressed={i === active} onClick={() => setActive(i)}>
          {p.label}
        </button>
      ))}
      {panels.map((p, i) => (
        <div key={p.label} hidden={i !== active}>
          {p.content}
        </div>
      ))}
    </section>
  );
}
  1. Tabs does not import Reviews. It only declares that it takes panels with a content of type ReactNode.
  2. It draws one button per panel and keeps the active index in state.
  3. It renders every panel and hides the inactive ones with hidden, so the text of every tab is in the initial HTML.

The Next.js boundary guide explains it with two roles React keeps apart. The owner is the component whose source contains the child's JSX: page.tsx writes <Reviews />, so it owns it. The parent is the one that contains it in the rendered tree: Tabs. Because the owner is a server component, Reviews renders on the server, and Tabs receives its output to place, never its code.

The 'use client' reference puts it this way: the boundary lives on the module dependency tree, not the render tree. Where a component appears says nothing about where it runs. Who imports it does.

children works the same way, because it is just another prop: a client modal or collapsible that wraps {children} can display server content. What does not work is importing the server component inside the client file. We tried it: a "use client" file that imported reviews.tsx broke the build, because it pulled lib/products.ts into the client graph:

./lib/products.ts
Error:   x You're importing a component that needs "server-only". That only works in a Server Component which is not supported in the pages/ directory.

Import trace for requested module:
./lib/products.ts
./app/p/[id]/reviews.tsx
./app/bad/tabs-bad.tsx

Without server-only, the error would have been a different one or, worse, none at all: the module would have shipped to the browser. That is why it belongs in every file that reads data or secrets.

What reaches the browser: HTML, RSC Payload and JavaScript

On the first load, according to the Next.js guide, the browser receives three things: the HTML, which shows the page right away even though it does not respond yet; the RSC Payload, a serialized representation of the Server Component tree; and the JavaScript for the Client Components, which hydrates them. On later navigations inside the site, only the payload arrives, and Client Components render in the browser.

what reaches the browser on first loadHTML<h1>Tenis Ruta</h1>size buttonsreviews as texthidden shipping panelRSC Payloadoutput of ReviewsI[2710] AddToCartI[3790] Tabsprops: productId,sizes, panelsJavaScriptAddToCart + Tabs965 B, not gzippeduseState, onClicknever sent: the code of Reviews, getReviews or costCentsthe payload format is internal to Reactoutput, references and props, not codelocal demo: Next.js 15.5.23, next build and next start

Scroll the figure sideways to see all of it

We requested the page's payload with the RSC: 1 header. These are four of its lines, verbatim. The format is internal to React and may change: read it to understand the model, not to depend on it.

e:I[2710,["841","static/chunks/app/p/%5Bid%5D/page-e5fb1ad810c9ab0d.js"],"default"]
f:I[3790,["841","static/chunks/app/p/%5Bid%5D/page-e5fb1ad810c9ab0d.js"],"default"]
4:["$","main",null,{"children":[["$","h1",null,{"children":"Tenis Ruta"}],["$","p",null,{"children":"$$1,899.00"}],["$","$Le",null,{"productId":"1","sizes":["25","26","27"]}],["$","$Lf",null,{"panels":[{"label":"Reseñas","content":"$L10"},{"label":"Envío","content":["$","p",null,{"children":"Envío gratis desde $999."}]}]}]]}]
10:["$","ul",null,{"children":[["$","li","Ana",{"children":["★★★★★"," ","Cómodos desde el primer día."," (","Ana",")"]}],["$","li","Luis",{"children":["★★★★"," ","La talla es exacta."," (","Luis",")"]}]]}]
  1. e and f are references to Client Components: module 2710 (AddToCart) and module 3790 (Tabs), plus the JavaScript file each lives in.
  2. Line 4 is the page's output: a main with the h1 and the price already computed (the $$ is an escaped $). $Le is a slot for AddToCart with its productId and sizes props; $Lf is Tabs with its panels.
  3. The reviews panel points to $L10, and line 10 is a ul with the review text. There is no trace of Reviews or getReviews: only their result.

On the JavaScript side, the page chunk is 965 bytes uncompressed and holds two modules: AddToCart and Tabs. We searched every file in .next/static for the review text, getReviews and the product cost: none of them are there.

Whatever you pass as a prop is published

Data crosses the boundary through props, and props get serialized. In the demo, the product has an internal field, costCents, what the store pays for it. With productId and sizes it stays put. In a variant of the page we passed the whole object to a client component that only used the name, and this showed up in the payload, and inside the HTML too:

4:["$","$Le",null,{"product":{"id":"1","name":"Tenis Ruta","priceCents":189900,"costCents":74250,"sizes":["25","26","27"]}}]

Anyone who views the page source can read it. TypeScript does not warn you, because the type is correct. The rule: pass leaves only the fields they use. It is the same principle as with environment variables: what reaches the client is public, as we explain in NEXT_PUBLIC_ and secrets.

Not everything can be serialized. React accepts primitives, arrays, Map, Set, Date, plain objects, JSX, promises and Server Functions. It rejects classes, class instances and plain functions. We passed a function to format the price, and the build stopped at prerender, even though tsc did not complain:

Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with
"use server". Or maybe you meant to call this function rather than return it.
  {cents: 189900, format: function format}
                          ^^^^^^^^^^^^^^^

The fix is what the demo already does: format on the server and pass the string.

Initial HTML and LCP

Because Server Component content is already in the HTML, the browser can paint it and discover the hero image without waiting for JavaScript. We compared it with an older version of the same page: a "use client" page that fetched the product from an API route inside useEffect. Its initial HTML only contained "Cargando…" (loading); the product name appeared after hydration and the request. If that page had a photo, the largest image would arrive late too, which is exactly what hurts the LCP of your hero image.

Common mistakes

  • Thinking 'use server' marks a Server Component. They have no directive; 'use server' is for Server Functions.
  • Thinking a Client Component only runs in the browser. It also renders on the server for the initial HTML, which is why touching window outside an effect fails.
  • Importing a Server Component inside a client file. It turns into client code, or breaks the build if it uses server-only. Pass it as children or as a prop.
  • Passing whole objects to leaves. Every field travels in the payload and the HTML, internal ones included.
  • Passing functions as props. The build fails at prerender. Compute on the server or use a Server Function.
  • Fetching in useEffect data the server already has. It delays the content and adds a request.
  • Wrapping the whole <html> in a context provider. The Next.js guide asks you to render providers as deep as possible, wrapping only {children}.

Frequently asked questions

Does a Server Component re-render when its child's state changes?

No. The state lives in the client component and updates in the browser. A Server Component only renders again when Next.js renders the route again: a navigation, a refresh or a revalidation.

Can a Client Component be async?

No. Async components are server components. If a Client Component needs server data, take it as a prop, or take a promise started on the server and read it with use inside a Suspense boundary.

Do Server Components help SEO?

They help put content in the first HTML, which is what a crawler that does not run JavaScript reads. Client Components also contribute HTML to that render; what is missing is content that depends on an interaction or an effect.

How do I tell if a component with no directive is server or client?

Look at who imports it. If a 'use client' module or anything below it imports it, that usage is client. If a Server Component imports it, it is server. The same file can be both in different places.

Checklist

  • Pages and layouts have no 'use client'.
  • Every client component uses state, events, effects, browser APIs or context.
  • Interactive parts are small leaves, each in its own file.
  • Server content enters client components as children or another prop, never as an import.
  • Leaves get only the fields they use, no whole objects.
  • You do not pass plain functions as props to client components.
  • Files that read data or secrets start with import "server-only".
  • First-load data is read by a Server Component, not by a useEffect.
  • You checked one page's HTML and payload (RSC: 1) for internal fields.

Once the tree is clear, deciding where each component goes becomes a short question: does it need the browser? If not, it stays on the server.

Native HTML also covers some interactivity without shipping JavaScript, such as the Popover API. And when a Server Component receives outside data, validate it at the door with zod.

Saw this on Instagram? Every Reel guide is at ecomlabs.dev/guides.

Written by

Luis Morales

Luis Morales

Frontend and Shopify developer, EcomLabs

@luismoralesdev on Instagram

Published November 19, 2026 · updated November 20, 2026

← Blog