Place client boundaries around behavior
A visual Next.js walkthrough of imports, server-created children and a small reading preference that belongs in the browser.

A reading page gains a “Large text” button. The button needs state; the article, publication details and source list do not. When the build asks for a client boundary, placing it at the top of the page is an easy fix. It also changes which imported modules enter the browser side of the application. Choose that boundary as deliberately as you choose the control itself.
Start with the behavior, then inspect imports
In the App Router, pages and layouts are Server Components by default. State, React event handlers and browser APIs call for Client Components. The Next.js component guide recommends putting the client entry near interactive UI. For our reading page, a small ReadingTools component can own the size preference while the page still assembles the article.
Draw two lists before editing: what changes when the reader presses the button, and what the proposed client file imports. The first explains the feature; the second exposes its dependency cost. A heading can be visually quiet and still enter the client graph if an interactive ancestor imports its module. Splitting files alone does not change that.
Original module diagram. Arrows mean imports. Blue marks the client graph, not a measured amount of JavaScript. Shared dependencies and framework runtime are omitted.React defines the directive’s reach through the module dependency tree, including transitive imports. You do not need to label every descendant file. Conversely, the absence of a directive in a dependency does not guarantee server execution. Review imports from the client entry outward, including shared formatting helpers and UI libraries.
Choose a boundary that fits the job
Page owns all behavior
Useful when most of the page is one coordinated interactive workspace.
- State can be shared directly across the workspace.
- Imported page sections join the client graph.
- Audit the dependencies of the whole entry.
A focused control owns state
A good starting point for a reading page with a local preference.
- ReadingTools owns the text-size toggle.
- The page prepares the article independently.
- Pass only the values or rendered content the control needs.
Visual nesting does not decide the boundary
Our toolbar should wrap the article so its text-size style can apply to the reading region. That does not require ReadingTools to import ArticleBody. Let the server page create both elements and pass the body through children. React’s composition explanation distinguishes this rendered relationship from a module import: the client wrapper receives the server-created result, rather than the body component’s implementation.
Original composition diagram. The server page owns both elements. ReadingTools displays the supplied body and owns only its local text-size preference.// app/page.tsx — server entry
import ReadingTools from './reading-tools';
import ArticleBody from './article-body';
export default function Page() {
return (
<ReadingTools>
<ArticleBody />
</ReadingTools>
);
}
// app/reading-tools.tsx
'use client';
import {
useState, type ReactNode
} from 'react';
type Props = { children: ReactNode };
function ReadingTools(
{ children }: Props
) {
const [large, setLarge] =
useState(false);
const size = large ? '1.2em' : '1em';
const toggle = () =>
setLarge(v => !v);
return (
<section>
<button
aria-pressed={large}
onClick={toggle}
>
Large text
</button>
<div style={{ fontSize: size }}>
{children}
</div>
</section>
);
}
export default ReadingTools;
These structural excerpts assume a separate ArticleBody component and typography that inherits the wrapper’s size; fixed descendant font sizes will not follow it. The toggle is a local reading preference, not a substitute for browser zoom. A complete implementation still needs readable focus styling and checks with actual long-form content. No bundle reduction or runtime benchmark is claimed here.
Keep the boundary contract explicit
Props crossing into a client entry must use React-supported serialization. Pass the article result or a small set of display values. Define the ordinary click handler inside ReadingTools instead of passing a server-created callback. React supports more than plain JSON, including JSX; the exact supported types are listed in the React reference. Server Functions have a separate reference mechanism, so “no functions ever” would be an inaccurate rule.
Review the crossing| Boundary crossing | Question |
|---|
| Imported modules | Only needed dependencies? |
| Serialized props | Allowed type and intended audience? |
| Rendered children | Server output or client import? |
| Local preference | Owned by this reading region? |
The Next.js boundary guide explains that distinction and the browser behavior already available through HTML. For a simple disclosure, a native details element may meet the requirement without React state. For this size toggle, client state is purposeful. Pick the behavior first; avoid adding a client component merely because a design contains a button-shaped element.
Review the split with the actual page
A focused boundary review
Write the observable change
“Large text changes the reading region and exposes its pressed state.” Name which surrounding content should remain unaffected.
Trace the import graph
Start at ReadingTools and list its dependencies. Keep the article preparation out of that graph; use server-created children where composition fits.
Review transmitted values
Inspect props and rendered output. Server origin does not make delivered content private. A server-only import guard can catch accidental client imports of protected modules.
Test the reading experience
Build the real app, inspect its initial HTML, and exercise the toggle by keyboard at narrow and wide widths. Check headings, links and long paragraphs after enlarging text. Measure emitted client code before claiming a saving.
The server-only guard described by Next.js catches an environment mistake at build time; it does not replace access control or careful prop selection. The practical review question is smaller: can another maintainer explain why this module needs browser execution, what it imports, and what it receives? If those answers fit the feature, the boundary is easier to keep intentional as the page grows.
Back to the LOOKFILE blog