---
title: "React Server Components: what runs on the server and what runs in the browser"
description: "A clear mental model for React Server Components: which code runs on the server, which ships to the browser, what can cross the boundary and where to put use client."
url: https://www.danny.engineering/article/react-server-components-what-runs-on-the-server-and-what-runs-in-the-browser
author: Danny
published: 2026-12-02T00:00:00.000Z
updated: 2026-12-01T21:22:00.000Z
tags: ["React", "Next.js"]
---

# React Server Components: what runs on the server and what runs in the browser

You add a `console.log` to a component and it shows up in your terminal instead of the browser. You add `useState` and the build fails. You mark a file with `'use client'` and suddenly a database library is being bundled for the browser. If any of that sounds familiar, the problem is usually not the code. It is the mental model of where each piece of it runs.


This article is for React developers working with Server Components, most often through the Next.js App Router. We will build a picture of the two environments, look at how the boundary between them works, and finish with patterns for real pages and the cases where Server Components are not the right tool.


## Two environments, one tree


With Server Components, a single React tree is split across two environments.

- **Server Components** run only on the server. That can be at build time, when a page is prerendered, or at request time. Their code is never sent to the browser.
- **Client Components** are the components you already know. They can use state, effects and event handlers, and their code is sent to the browser.

The name "Client Component" is a little misleading. A Client Component also runs on the server during the first render, so the user gets HTML straight away. Then it runs again in the browser to hydrate that HTML and make it interactive. So the more accurate rule is:

- Server Components run on the server only.
- Client Components run on the server for the initial HTML and in the browser from then on.

When a Server Component renders, React does not produce HTML directly. It produces the RSC payload, a serialised description of the tree. Where the tree contains a Client Component, the payload holds a reference to that component's JavaScript file plus the props to pass it. The framework uses the payload to build HTML for the first load, and the browser uses it to reconcile the tree on later navigations.


## Server Components are the default


In the Next.js App Router, every component in the `app` directory is a Server Component unless you say otherwise. That means you can make it `async` and fetch data directly.


```typescript
// app/articles/page.tsx
import { db } from "@/lib/db";

export default async function ArticlesPage() {
  const articles = await db.article.findMany({
    where: { published: true },
    orderBy: { date: "desc" },
  });

  return (
    <ul>
      {articles.map((article) => (
        <li key={article.id}>{article.title}</li>
      ))}
    </ul>
  );
}
```


None of this code reaches the browser. The database client, the query and any secrets it reads stay on the server. The browser only receives the rendered list.


What a Server Component cannot do is anything that needs to exist in the browser after render:

- `useState`, `useReducer` or `useEffect`
- event handlers such as `onClick` or `onChange`
- browser APIs like `window`, `localStorage` or `IntersectionObserver`
- context providers and consumers created with `createContext`

If you try, you get a build error telling you the component needs to be a Client Component.


## Marking the boundary with use client


The `'use client'` directive goes at the top of a file, before any imports.


```typescript
// app/articles/like-button.tsx
"use client";

import { useState } from "react";

export function LikeButton({ initialCount }: { initialCount: number }) {
  const [count, setCount] = useState(initialCount);

  return (
    <button onClick={() => setCount((c) => c + 1)}>
      Like ({count})
    </button>
  );
}
```


The important detail is that `'use client'` marks a boundary in the module graph, not a single component. Everything that file imports, and everything those files import, becomes part of the client bundle. So if a Client Component imports a large date library or a markdown parser, that library now ships to the browser.


This is why the usual advice is to push `'use client'` towards the leaves of the tree. Keep the page, the layout and the data fetching in Server Components, and mark only the small interactive parts as Client Components.


```typescript
// app/articles/[id]/page.tsx (Server Component)
import { getArticle } from "@/lib/articles";
import { LikeButton } from "./like-button";

export default async function ArticlePage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const article = await getArticle(id);

  return (
    <article>
      <h1>{article.title}</h1>
      <div dangerouslySetInnerHTML={{ __html: article.html }} />
      <LikeButton initialCount={article.likes} />
    </article>
  );
}
```


The article body is rendered on the server and arrives as HTML. Only `LikeButton` and its tiny dependency tree are sent as JavaScript.


## What can cross the boundary


When a Server Component renders a Client Component, the props are serialised into the RSC payload. That means they must be values React knows how to serialise. The supported types include:

- strings, numbers, booleans, `null`, `undefined` and `bigint`
- plain objects and arrays made of supported values
- `Date`, `Map`, `Set`, typed arrays and `ArrayBuffer`
- JSX elements, including other Server Components
- Promises
- Server Functions

What cannot cross is anything that only makes sense in memory on the server: ordinary functions, class instances and symbols that are not registered globally.


```typescript
// This fails: a plain function is not serialisable
<Filter onChange={(value) => console.log(value)} />

// This fails: a class instance loses its prototype
<Profile user={new User(row)} />

// This works: pass plain data instead
<Profile user={{ id: row.id, name: row.name }} />
```


A good habit is to map database rows to small plain objects before passing them down. It keeps the payload small and stops you accidentally sending columns, such as an email address or a password hash, that the browser should never see. Every prop you pass to a Client Component ends up in the page source.


## Server Components inside Client Components


A Client Component cannot import a Server Component. Once you are inside a client module, everything it imports is client code. But a Client Component can receive a Server Component as a prop, most often as `children`.


```typescript
// app/components/collapsible.tsx
"use client";

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

export function Collapsible({
  title,
  children,
}: {
  title: string;
  children: ReactNode;
}) {
  const [open, setOpen] = useState(false);

  return (
    <section>
      <button onClick={() => setOpen(!open)}>{title}</button>
      {open && children}
    </section>
  );
}
```


```typescript
// app/page.tsx (Server Component)
import { Collapsible } from "./components/collapsible";
import { RecentComments } from "./components/recent-comments";

export default function Page() {
  return (
    <Collapsible title="Recent comments">
      <RecentComments />
    </Collapsible>
  );
}
```


`RecentComments` is still a Server Component. It is rendered on the server and its output is slotted into the client wrapper. This pattern is how you keep context providers, tabs, modals and other interactive shells on the client without dragging everything inside them into the bundle.


## Streaming data with promises


Because Promises can be passed as props, a Server Component can start a slow request and hand the unresolved promise to a Client Component. The client reads it with `use`, and a `Suspense` boundary shows a fallback until it resolves.


```typescript
// app/dashboard/page.tsx (Server Component)
import { Suspense } from "react";
import { getStats } from "@/lib/stats";
import { StatsChart } from "./stats-chart";

export default function Dashboard() {
  const statsPromise = getStats(); // not awaited

  return (
    <Suspense fallback={<p>Loading stats…</p>}>
      <StatsChart statsPromise={statsPromise} />
    </Suspense>
  );
}
```


```typescript
// app/dashboard/stats-chart.tsx
"use client";

import { use } from "react";
import type { Stats } from "@/lib/stats";

export function StatsChart({ statsPromise }: { statsPromise: Promise<Stats> }) {
  const stats = use(statsPromise);
  return <pre>{JSON.stringify(stats, null, 2)}</pre>;
}
```


The rest of the page is sent immediately, and the chart streams in when the data arrives.


## use server is not the opposite of use client


This trips up a lot of people. There is no `'use server'` directive for Server Components. Server Components need no directive at all, because they are the default.


`'use server'` marks **Server Functions**: async functions that run on the server but can be called from the client, for example from a form action or an event handler.


```typescript
// app/articles/actions.ts
"use server";

import { db } from "@/lib/db";

export async function likeArticle(id: string) {
  await db.article.update({
    where: { id },
    data: { likes: { increment: 1 } },
  });
}
```


A Client Component can import `likeArticle` and call it. React turns the call into a network request. Treat every Server Function like a public API endpoint: check who is calling it and validate its arguments, because anyone can send that request.


## Keeping server code on the server


It is easy to import a server-only module into a Client Component by accident, especially through a shared utility file. Two things help.


First, the `server-only` package. Import it at the top of any module that must never reach the browser, and the build fails if a client module imports it.


```typescript
// lib/db.ts
import "server-only";

export const db = createDatabaseClient(process.env.DATABASE_URL);
```


Second, environment variables. Next.js only inlines variables prefixed with `NEXT_PUBLIC_` into client code. Anything else is `undefined` in the browser, which protects secrets but can also confuse you if a Client Component reads a variable that works fine on the server.


## A quick reference


| Question                                    | Server Component | Client Component                          |
| ------------------------------------------- | ---------------- | ----------------------------------------- |
| Runs at build or request time on the server | Yes              | Yes, for initial HTML                     |
| Runs in the browser                         | No               | Yes                                       |
| Code sent to the browser                    | No               | Yes                                       |
| Can be async and await data                 | Yes              | No, use `use` with a promise              |
| State, effects, event handlers              | No               | Yes                                       |
| Can read secrets and the database           | Yes              | No                                        |
| Where console.log appears                   | Terminal         | Browser console (and terminal during SSR) |


In development, React also replays Server Component logs in the browser console, labelled as coming from the server, which helps when you are not watching the terminal.


## Version support


Server Components have been stable since React 19.0, and the current release line is React 19.3. They need a framework or bundler integration to work, because something has to split the module graph and serve the RSC payload. The Next.js App Router is the most widely used option and is where most of these examples come from. Other frameworks have their own integrations at different levels of maturity, so check your framework's documentation before relying on them.


Keep `react`, `react-dom` and your framework on their latest patch releases. Server Components and Server Functions accept requests from the network, and security fixes for that machinery have shipped as patch releases.


## When not to use it


Server Components are a good default for content-heavy pages, but they are not free.

- **Highly interactive apps.** A drawing tool, a spreadsheet or a dashboard where nearly everything responds to input will end up mostly client code anyway. The extra boundary adds complexity without saving much JavaScript.
- **Apps with no server.** If you deploy static files to a CDN and talk to a separate API, a client-rendered app or a static site generator may be simpler.
- **Widgets embedded in other sites.** A component you drop into someone else's page has no React server behind it.
- **Teams new to React.** The two-environment model is one more thing to learn. If your app is small, a plain client-side React app is fine.

## Wrapping up

- Server Components run only on the server and send no JavaScript. Client Components render on the server first, then run in the browser.
- `'use client'` marks a boundary in the module graph. Everything a client file imports ships to the browser, so keep the directive near the leaves.
- Props crossing the boundary must be serialisable. Pass plain data, and remember it all ends up in the page source.
- Pass Server Components to Client Components as `children` rather than importing them.
- `'use server'` is for Server Functions, which are public endpoints. Validate and authorise every call.
