(Note · · 6 min read)

Adding "use client" until the error goes away

You hit an error about hooks or event handlers, add "use client" to the top of the file, and it compiles. Repeat that a dozen times and the application is client-rendered with extra steps, which is the common way an App Router project ends up slower than the pages-based one it replaced.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

The directive is a boundary, not a fix

"use client" does not mark one component as interactive. It marks the start of a boundary: that module and everything it imports become part of the client bundle. Put it at the top of a page that imports half the application and you have shipped half the application.

So the question is never does this file need it, it is where is the smallest possible boundary. Usually that is a leaf — the button that needs onClick, the panel that needs state — not the page that contains it.

Push the boundary down, and pass children through

The move that resolves most of these is composition. A client component can render server-rendered content passed to it as children, because that content was already rendered elsewhere and arrives as a prop rather than an import.

Interactivity around server content
// Accordion.tsx — "use client", holds the open state
// page.tsx — a server component
<Accordion>
  <ExpensiveServerRenderedList />   {/* stays on the server */}
</Accordion>

That inverts the usual instinct, which is to move the parent to the client so it can hold the state. Hold the state in a small wrapper instead and let the expensive content remain where it was.

What cannot cross the boundary

Props passed from a server component to a client one have to be serialisable: no functions, no class instances, no anything that depends on a closure. The error for this is confusing the first time, and the fix is usually to pass an identifier and let the client component act on it, rather than passing behaviour.

Secrets are the more serious version. A value read on the server and passed as a prop is in the HTML sent to the browser. Anything prefixed to be public is public by definition, and anything not prefixed must never reach a client component's props.

Fetch where the data is used

Server components can fetch directly, so a component that needs data should get it rather than receiving it through several layers of props. That removes most of the waterfall problems people attribute to the router.

Where several independent things are needed, start them together rather than awaiting each in turn, and use loading boundaries so a slow section does not hold the rest of the page. Sequential awaits in a layout are the most common cause of a page that feels slower than its slowest query.

How to tell whether it went wrong

Look at the client bundle rather than trusting the structure. If a page that is mostly static content ships a large bundle, a boundary is higher than it should be, and the import that pulled it there is usually a shared module that happens to contain one interactive export.

Splitting that module so the interactive part lives alone is dull work with an outsized effect, because every importer stops paying for it.

Common questions

What does "use client" actually do?

It marks the start of a client boundary: that module and everything it imports join the client bundle. It is not a per-component flag, which is why placing it on a page that imports widely ships far more JavaScript than intended.

How do I keep server rendering while adding interactivity?

Push the boundary to the smallest leaf and pass server-rendered content through as children. A client component can render children it receives as props, so expensive content stays on the server while a small wrapper holds the state.

Why can't I pass a function as a prop to a client component?

Props crossing the boundary must be serialisable, so functions, class instances and closures cannot cross. Pass an identifier and let the client component act on it instead of passing behaviour.

Can a server secret leak through props?

Yes. A value passed from a server component to a client component is embedded in the HTML sent to the browser. Keep anything not explicitly public out of client component props entirely.

Need something like this built?