RSC and Server Actions in practice: where to put "use client"
Plenty has been written about React Server Components, but most articles try to explain them. I want to write about something else: which rules turned out to be useful after a year of actually working with them.
The shortest conclusion is this: all of the complexity in RSC collapses into one decision — where you put `"use client"`.
The boundary is contagious downward
The first and most expensive lesson: "use client" marks not a file but an entire branch.
If you mark a component as a client component, everything it imports goes to the client too. And their imports as well. The chain continues downward without limit.
The practical consequence is this. Say there is one small interactive element near the top of the page — a theme toggle, for instance. Put "use client" at the layout level and the whole page moves to the client.
The right answer is to push the boundary as far down as possible:
// app/[lang]/blog/page.tsx — a server component
import { LikeButton } from './like-button'
export default async function BlogPage() {
const posts = await getPosts() // on the server
return (
<main>
{posts.map((p) => (
<article key={p.slug}>
<h2>{p.title}</h2>
<LikeButton slug={p.slug} /> {/* only this on the client */}
</article>
))}
</main>
)
}// like-button.tsx
'use client'
export function LikeButton({ slug }: { slug: string }) {
const [count, setCount] = useState(0)
return <button onClick={() => setCount((c) => c + 1)}>{count}</button>
}Only the button ships to the client here. Article text, headings, data fetching — all of it stays on the server.
When you genuinely need "use client"
The list is short and easy to memorise. A client component is needed when you have:
useState,useReducer,useEffectand other hooks- Event handlers:
onClick,onChange,onSubmit - Browser APIs:
window,localStorage,IntersectionObserver - Libraries that only run in the browser
Everything else can and should be a server component.
The inverse question is useful too: is this component not interactive at all? If not, it has no business on the client.
Where to get data
The biggest practical benefit of RSC is that fetching data no longer requires an API endpoint.
The old flow was: a component calls fetch inside useEffect, that hits /api/posts, and that talks to the database. Three layers.
Now the server component asks directly:
export default async function Page() {
const posts = await db.select().from(postsTable)
return <PostList posts={posts} />
}No intermediate layer. That reduces code and removes one source of bugs — type drift between the API and the component.
An important detail: this code runs only on the server, so touching the database directly is safe. But precisely for that reason you must be careful: anything passed from a server component into a client component is visible to the user. Do not hand over a whole user object; pick the fields you need.
Server Actions: when they fit
Server Actions let you handle a form submission without writing an API.
async function addComment(formData: FormData) {
'use server'
const text = formData.get('text') as string
await db.insert(comments).values({ text })
revalidatePath('/blog')
}
export function CommentForm() {
return (
<form action={addComment}>
<textarea name="text" />
<button type="submit">Send</button>
</form>
)
}That is elegant, and I use it for simple forms.
But in two situations I still write a plain route handler.
The first is when you need a response. A Server Action can return a result, but once the flow gets complicated — validation errors, partial success, progress — an ordinary endpoint is clearer.
The second is when there is an external consumer. If a mobile app or another service calls your API, a Server Action is useless to them. It exists only for your page.
An important reminder: a Server Action is a public HTTP endpoint, merely hidden. It must carry authentication and validation. The assumption "this is only called from my form" is wrong.
The trap that makes a page dynamic
Now the most expensive lesson.
My blog articles were supposed to run through ISR: the page is generated ahead of time and refreshed every five minutes. That is configured in the code.
Then I measured, and found that not a single page was being pre-generated. Every one of them was built per request.
The cause was somewhere unexpected: the topmost layout called headers(). It was reading a language setting.
The rule is this: if headers(), cookies() or searchParams are called anywhere in the tree, the entire branch becomes dynamic. Static generation becomes impossible, because you cannot assemble the response without seeing the request.
The worst part is that this happens silently. No error, no warning. Your ISR setting stays exactly where it is and simply never takes effect.
Hence one practical habit: read the output of bun run build every time. It lists which routes are static and which are dynamic. If that list differs from what you expected, go find out why immediately.
In my case the fix would be removing headers() from the layout. I have not done it, for a simple reason: the blog pages are fast anyway and being dynamic does me no harm. What matters is that I know. There is no ambiguity.
Practical recommendations
The short list left after a year of work:
- The default is a server component.
"use client"goes in only with a specific reason. - Push the boundary as low as you can. The button should be the client component, not the page.
- Pass only the fields you need into client components, never whole objects.
- Server Actions for simple forms. For complex flows or external consumers, write a route handler.
- Every Server Action needs authentication and validation.
- Read the static/dynamic route list in your build output. An unexpected dynamic route is a signal to investigate.
That last point saves the most time, because most RSC mistakes never raise an error — they just silently turn off the optimisation you were counting on.