Client vs Server Boundary — 'use client' Changes Everything
Client vs Server Boundary — 'use client' Changes Everything
💡 Why Does This Matter? — The Server/Client Boundary Is the Boundary of Bundle Size and Security
3 Core Rules of the Boundary
1. What 'use client' Really Means
- ▸This file and every component this file imports become Client Components (it's contagious).
- ▸In other words, 'use client' marks the boundary of "the tree starting from here" — not just "this one component."
- ▸A single page can have multiple 'use client' boundaries, and that's perfectly normal.
2. Five Signals That You Need 'use client'
If any one of these is needed → 'use client'. Otherwise, keep it a Server Component.
3. Server → Client is OK, Client → Server is ❌
4. The Solution — Composition via the children Prop
Key insight: A Client Component cannot directly import a Server Component, but it's perfectly fine for the Server to pass Server-rendered JSX as a children prop to a Client Component. This is the most important pattern in App Router.
5. Common Pitfalls Inside Server Components
💡 💡 Five Rules for Drawing the Boundary Well
1. Push 'use client' as close to the leaf as possible
Adding 'use client' to large components like pages or layouts is almost always the wrong call. Reserve it for the small components that genuinely need interactivity (buttons, inputs, dropdowns).
2. Remember that 'use client' is contagious
Everything imported by a file marked 'use client' becomes a Client Component. Even a Server Component gets treated as a Client Component once it falls inside that import tree.
3. When you need Server content inside a Client, receive it via children
4. You can't add onClick in a Server Component — extract it into a Client leaf
The compiler will catch it as a build error, but knowing the pattern upfront saves time.
5. Even with 'use client', the component still renders on the server before hydration
The initial HTML is rendered on the server; the browser brings it to life via hydration. SSR always happens. 'use client' does not mean 'browser only' — it means 'also alive in the browser after hydration.'