Consent-first analytics in Next.js
How I wired GA4, Google Tag Manager and self-hosted Umami with Consent Mode v2 in Next.js, plus the GTM consent bug that silently dropped every first visit.
Server Components confuse people because the mental model is missing. Here's the kitchen picture that makes the split click, and the rules that keep it clean.

Forget the tech for a second. Picture a restaurant kitchen.
The kitchen preps everything out of sight. Raw ingredients, the walk-in fridge, the recipes nobody at the table should see. By the time a plate reaches you, the mess is gone. You get the finished dish, not the chopping board.
That's a React Server Component. It does its work on the server, close to the data, and sends the diner a finished plate. The browser never sees the fridge.
Once that picture is in your head, most of the confusing rules stop being rules. They become common sense about restaurants.
Not what the component looks like. Where it cooks.
A Server Component runs on the server. It can read the database, hold secrets, and pull in heavy libraries without shipping any of that to the browser. What the user receives is the result, not the machinery.
// Server Component (the default). Runs on the server, ships no JS of its own.
async function Post({ id }: { id: string }) {
const post = await db.post.findById(id) // the fridge, hidden from the diner
return <article>{post.body}</article>
}Notice the async. A Server Component can simply await its data during render. No effect, no loading flag, no second round trip from the browser.
A Client Component is the part of the meal the diner finishes at the table. The sizzling plate. The thing you poke, stir, and react to. State, effects, event handlers, browser APIs, anything that responds to a click lives here and ships as JavaScript.
"use client"
import { useState } from "react"
// Client Component. Ships to the browser because it needs to react.
export function LikeButton() {
const [liked, setLiked] = useState(false)
return <button onClick={() => setLiked(!liked)}>{liked ? "♥" : "♡"}</button>
}The Next.js docs split it cleanly, and the kitchen maps onto it almost line for line.
| Job | Kitchen (Server) | Table (Client) |
|---|---|---|
| Fetch from the database or an API | Yes, close to the source | Only through a request |
| Use API keys and secrets | Yes; never render or pass them to the client | Never |
| Heavy libraries (markdown, dates) | Yes, at no cost to the browser | Shipped to every visitor |
useState, useEffect, event handlers | No | Yes |
Browser APIs like localStorage | No | Yes |
Can be async | Yes | No |
The old model shipped the whole kitchen to every table. Your data-fetching code, your date library, your markdown parser, all bundled and sent to the browser so it could rebuild the page there. Fast laptops hid the cost. Budget phones on a patchy connection did not.
Server Components leave the kitchen in the back. The React docs show exactly this: a component that uses marked and sanitize-html to render markdown, where neither library ends up in the bundle. The browser gets the rendered output and nothing else. Less to download, less to parse, and your keys stay where the knives are.
Here's the part that surprised me, and it changes how you place the boundary.
"use client" doesn't mark a component. It marks a door. Once a file has it, its transitive module dependencies become part of the client graph. Server-rendered children passed from a server parent are a different case, explained below. So one careless "use client" at the top of a big page doesn't just move one component to the table. It wheels the whole prep station out into the dining room.
Keep the page a Server Component, and hand the one button that needs state its own small client island. The Next.js docs recommend exactly this to keep bundles small: put the directive on the interactive pieces, not on large chunks of UI.
A whole page marked
"use client"is a kitchen that sends every diner the raw ingredients. Technically it works. It also defeats the point.
The tricky part isn't either side. It's the pass between them. A few rules save most of the pain.
Props from a Server Component to a Client Component must be serializable. Strings, numbers, plain objects, arrays, dates: fine. A database connection or a class instance: no. A plain function: also no, with one useful exception. The "use client" reference allows Server Functions, the ones marked "use server", to be passed down. That's how a client form calls back into the kitchen without carrying the kitchen with it.
The plate travels. The fridge does not.
Client Components can't be async, and they can't read the database directly. If a client island needs data, the server hands it down as a prop, streams it as a promise the client unwraps with use, or the client asks through a request. Diners order. They don't raid the cold room.
A Client Component can't import a Server Component. It can accept one as children. Say you have a modal that needs client state to open and close, and a cart inside it that reads from the database. The modal is a client island with a children slot, the page passes the server-rendered cart into it, and both get to be what they are. Think of it as the server sliding a finished plate onto a trolley the waiter pushes.
Learn the seam and the rest is just React. Fight the seam and every feature feels like swimming upstream.
My pages are Server Components by default. I reach for "use client" only when a piece genuinely needs to react.
| Piece of UI | Where it lives | Why |
|---|---|---|
| Article body, case study, pricing table | Server | Pure content, no reason to ship JS |
| Navigation links, footer | Server | Static, and on every page |
| Search box, theme toggle | Client | Needs state and input |
| Forms | Client island, posting to a Server Function | Interactive on the table, saved in the kitchen |
| Animation, live clock | Client | Lives on the browser's timeline |
That rule ran through the IT Origin build: most of the site renders on the server and ships as HTML, with client JavaScript only where a human actually clicks, types, or watches something move. Small JavaScript is fast JavaScript; here is what it added up to in PageSpeed on this site. It's the same instinct behind the rest of my stack, and it's a big part of the framework call in Next.js vs TanStack Start. Do the heavy work where the data lives. Ship the diner a clean plate.
Take a hypothetical product page. The server loads the product and chooses the public fields. A small client component owns the quantity selector. The checkout operation authenticates the customer, checks stock and calculates the payable amount again on the server.
Now deliberately change the price in the browser's request. If checkout trusts it, the problem is authorisation and business validation, not where you placed "use client". A beautifully arranged kitchen still needs someone checking the bill.
Review three things: which modules enter the client bundle, which values cross as props, and which operations recheck permissions. Do not pass an entire database row because it is convenient; pass the fields the interface needs. A private note rendered into HTML is public even when the component producing it is server-only.
Also remember that Client Components can be prerendered on the server. Read browser-only APIs in an effect or event handler where appropriate, rather than assuming window exists during render. React's client-boundary reference explains the module boundary; typed validation handles a different part of the problem.
No, and the overlap causes half the confusion. SSR turns components into HTML on the server for a fast first paint, then hydrates the client parts in the browser so they become interactive. Server Components never ship their code to the browser at all. In Next.js you get both working together.
In the Next.js App Router, layouts and pages are Server Components by default, so you're already using them. You opt out with "use client" when a component needs interactivity. Most of your tree can stay on the server, and it usually should.
Yes, that's the normal pattern: a server page renders a client island. The reverse is limited. A Client Component can't import a Server Component, but it can receive one as children or another prop, which covers most real cases.
Usually one of two things. Passing a plain function as a prop across the boundary, or calling useState or useEffect in a file without "use client". Both throw clear errors once you know the seam exists, and both stop happening after the first week.
In the kitchen. Read them in Server Components or server-only modules, never in a file marked "use client". In Next.js, NEXT_PUBLIC_ variables are deliberately exposed to the browser bundle. Private values can still leak if you render them or pass them through client props, and the server-only package turns an accidental client import into a build error.
Server Components aren't a new framework to learn. They're a line drawn through the one you already know: heavy work in the kitchen, interactivity at the table, and a narrow, honest pass in between. Draw that line well and your pages get lighter, faster, and safer almost for free.
Curious how this shapes a full build? Here's why my APIs start with Hono and how I approach web development. And if you've got a Next.js project that feels heavier than it should, tell me what you're building. I'll show you where the kitchen leaked into the dining room.
Was this useful?
No account needed. One like per browser; click again to undo.
Prabir Singh
Full-stack engineer in Mumbai. Twenty years in sales taught me why people buy; seven years of code taught me how to build what they'll pay for. I still read error messages the way I once read objections: as the most honest feedback of the day. More about me or start a project.
How I wired GA4, Google Tag Manager and self-hosted Umami with Consent Mode v2 in Next.js, plus the GTM consent bug that silently dropped every first visit.
One language from the phone to the database. Why every project I take on is TypeScript end to end, and why I stopped apologising for it.
Express shaped a generation of Node APIs. Why my new backends start with Hono instead, where it changes how I build, and when Express still wins.