Next.js and React Server Components
Learn the Next.js App Router boundary between Server and Client Components, how serializable props cross it, and when React learners are ready.
Next.js App Router keeps pages and layouts on the server by default, then adds Client Components for state or browser APIs. This article follows an article page and like button across the boundary, showing which values can cross and why secrets stay server-side. It also explains how to check version-specific caching and Server Action behavior.
Next.js and React Server Components
Introduction
Once React components, props, state, and effects feel familiar, the App Router adds another question: which parts of a page need browser code, and which can stay on the server?
The examples below keep that boundary small. A page can load and render its content on the server while a single control handles interaction in the browser.
Version snapshot
These examples were checked against Next.js 16.4.6 and React 19.3 on November 23, 2026. In the App Router, pages and layouts are Server Components by default. A file with "use client" starts a Client Component module graph; its imports are included in that graph too. Client Components can still be pre-rendered as HTML for the first response. The label describes where their interactive code runs, not whether the browser receives HTML first.
Caching behavior depends on the Next.js version and configuration. In Next.js 16, setting cacheComponents: true enables Cache Components and APIs such as "use cache" and cacheLife. Without that setting, the previous caching model applies. The defaults differ, so check the guide for your app instead of assuming every server fetch is cached. See the guides for Cache Components and the previous caching model.
Next.js calls an async server function a Server Function. When you use one for an action or mutation, it is also called a Server Action. A function marked with "use server" can be invoked over a network request, so authenticate and authorize inside the function. It is an explicit server call, not an ordinary callback passed through props.
App Router starts on the server
App Router pages and layouts are Server Components unless you add a client boundary. State, event handlers, effects, and browser APIs need client execution. A file marked with "use client" becomes an entry point; its imports and imported descendants join the client module graph. Server-rendered content passed as children can remain outside that graph. Keep the boundary close to the interactive feature.
When to use each
Use Server Components for data loading and content that does not need browser APIs. Add a Client Component when a control needs state or event handlers. If one button needs state, leave the surrounding page on the server. A client-only app may not need this split.
Pass data across a small boundary
A Server Component can load an article and pass the values a like button needs. Props must be serializable by React. Plain values such as strings, numbers, booleans, arrays, and objects with serializable fields are easy to inspect. React supports a defined set of other values too; see its serialization rules before passing less common types. Ordinary callbacks cannot cross this boundary. Server Functions are a specific exception.
Here is the too-wide version: putting "use client" on the route just to make the like button work also puts the article body and its imports in the client module graph.
// Before: app/posts/page.tsx
"use client";
import { useState } from "react";
import ArticleBody from "./ArticleBody";
export default function Page() {
const [likes, setLikes] = useState(0);
return (
<main>
<ArticleBody />
<button onClick={() => setLikes((count) => count + 1)}>
Like ({likes})
</button>
</main>
);
}
Keep the route server-rendered and move only the button behind the client boundary:
// app/posts/page.tsx - Server Component by default
import LikeButton from "./LikeButton";
import { getPost } from "@/lib/posts";
export default async function Page() {
const post = await getPost(); // returns title, body, and likes
return (
<main>
<h1>{post.title}</h1>
<p>{post.body}</p>
<LikeButton initialLikes={post.likes} />
</main>
);
}
// app/posts/LikeButton.tsx
"use client";
import { useState } from "react";
export default function LikeButton({ initialLikes }: { initialLikes: number }) {
const [likes, setLikes] = useState(initialLikes);
return (
<button onClick={() => setLikes((count) => count + 1)}>
Like ({likes})
</button>
);
}
Only the button needs client-side interaction. Next.js can still pre-render its initial HTML. This example changes the count locally; a real app should save through a Server Action or Route Handler and check authorization on the server.
Follow the boundary
flowchart LR
A[Server page loads data] --> B[Serializable props]
B --> C[Small Client Component]
C --> D[State and event handler]
D --> E[Interactive browser UI]
Trade-off table
| Choice | Useful when | Cost |
|---|---|---|
| Server Component | Loading data or rendering mostly static content | Cannot use browser state or event handlers |
| Small Client Component | A control needs state or browser APIs | Adds JavaScript for that interactive part |
| Broad Client boundary | Most of a tool is genuinely interactive | Pulls more imports into the client module graph |
Production failure scenarios
Adding "use client" to a whole page to fix one button makes its imported descendants part of the client graph. Extract the button and keep the page server-rendered.
Passing a server-only object or non-serializable callback through props can fail at the boundary or expose fields the browser does not need. Select the small serializable fields the client component uses, and keep operations on the server.
Security notes
Data passed to a Client Component is serialized for browser use, so keep API keys and private records on the server and send only the fields the control needs. Environment variables without the NEXT_PUBLIC_ prefix stay in the server environment; prefixed values are bundled for browser code. Add import "server-only" to modules that must never enter the client graph. Authenticate and authorize sensitive operations on the server, including Server Actions.
Common mistakes
Do not add "use client" everywhere, pass ordinary functions across the boundary, or call browser APIs on the server. Imports beneath a client boundary join its graph. A Server Component passed as children can remain server-rendered, but start with a small boundary.
Observability checklist
- Track server data-load and client interaction failures separately.
- Check client bundle growth when boundaries move upward.
- Log safe record IDs, not secrets or full private data.
Are you ready for the App Router?
You are ready when props and state make sense, and you can build a component with a handler, manage an effect, validate API data, and test what the user sees. If those pieces still feel shaky, build another small React feature before adding the server/client boundary.
Quick recap
- App Router pages and layouts are Server Components by default.
- Use Client Components for state, handlers, effects, and browser APIs.
- A
"use client"file brings its imported descendants into the client graph. - Pass only the serializable values the client component needs.
- Keep secrets and authorization checks on the server.
- Check caching and Server Action behavior against the installed Next.js version.
Interview questions
No. In the App Router, pages and layouts are Server Components unless a client boundary is introduced.
It marks a client entry point and brings its imported descendants into the client module graph.
React must be able to serialize a prop into the server/client payload. For this button, a number is enough; an ordinary callback is not.
Files such as app/page.tsx and app/layout.tsx are Server Components by default.
- They can load data in the server environment.
- Use a client boundary only where browser interactivity is needed.
Use a Client Component when you need useState, an event handler, an effect, or a browser API.
- Place the directive before imports in the client entry file.
- Keep the boundary close to the interactive behavior.
Imports beneath a client entry point join its module graph and can increase the JavaScript sent to browsers.
- A broad boundary can increase client JavaScript.
- Keep imported client code small when possible.
Pass the smallest data shape that lets the control work, such as an initial count instead of a whole database record.
- Ordinary callbacks and server-only objects do not belong in these props.
- Keep the data shape small and explicit.
Keep the route on the server and extract the button into a Client Component. The article text does not need state or event handlers.
- This limits the client module graph.
- The server page can keep its data loading and static content.
Yes. A Server Component can render a Client Component and pass server-rendered JSX through its children prop.
- The server-rendered content can remain outside the client module graph.
- Keep the interactive part as the client entry point.
Keep credentials and private fields on the server. A client component's props and rendered content are available to the browser.
- Anything passed to the client can reach the browser.
- Keep authorization checks and sensitive operations on the server.
Further reading
- Review component boundaries and project structure for organizing small client islands.
- React state with useState covers state needed by interactive client components.
- Learn effect cleanup and browser synchronization in React effects with useEffect.
- For runtime data checks, see fetching and typing API data.
- Practice visible component behavior with component and interaction testing.
- Read the official Next.js guides to Server and Client Components, the
use clientdirective, Server Functions and Actions, and cache revalidation. React’suse clientreference lists the values that can cross the boundary. - For version notes, see the official Next.js 16 upgrade guide and React versions page.
Conclusion
Keep the article page on the server and let only the like button own client state. That keeps data loading near the server and limits the JavaScript needed for this interaction.
Category
Related Posts
Accessible React UI: Semantics, Labels, and Keyboard Use
Build React interfaces with semantic controls, connected labels, visible keyboard focus, and status announcements through practical TypeScript examples.
Advanced React State: When Local State Stops Fitting
Learn when React state needs a reducer and context, when Redux Toolkit helps, and why server data often belongs in a query cache instead.
Testing React Components and User Interactions
Write behavior-first React tests with accessible roles, realistic user events, and async assertions while avoiding brittle checks of implementation details.