Skip to content

No. 44Next.js8 min read2,041 words

Next.js App Router rendering: a practical mental model

How rendering works in the Next.js App Router: Server vs Client Components, static vs dynamic routes, streaming and Partial Prerendering, for builders.

Written by
Lazy Devs
Published
Updated
Sources
Cited inline

Key takeaways · 05

The short version

  1. 01In the App Router every component is a Server Component unless its file, or a file that imports it, starts with 'use client'. Server Components send no JavaScript of their own to the browser.
  2. 02Client Components still render to HTML on the server for the first load. 'use client' means 'also ship this to the browser and hydrate it', not 'render only in the browser'.
  3. 03Put 'use client' on the smallest interactive leaf. Marking a page or layout as a client component pulls everything it imports into the browser bundle.
  4. 04Rendering is a spectrum, not a switch: with Cache Components, a single route can have a prerendered static shell plus dynamic sections streamed at request time (Partial Prerendering).
  5. 05Read the next build output after every significant change. A route you expected to be static that shows up as dynamic usually means one stray cookies(), headers() or searchParams read.
On this page · 11

The Next.js App Router renders every component on the server by default, sends the browser HTML plus a compact description of the component tree, and ships JavaScript only for components marked "use client". Whether that server rendering happens once at build time or on every request depends on what the component reads: request data like cookies makes it dynamic, everything else can be prerendered. Hold those two ideas, where code runs and when it runs, and most App Router behaviour stops being surprising.

The confusion comes from the fact that the same file can run in three places: at build time, on the server per request, and in the browser. Stay fuzzy on which is which and you end up with a slow site, a large client bundle and a "why is this re-rendering" bug you cannot explain. Here is the model we use day to day on every web app we build.

Where code runs: the three places

WhereWhen it runsWhat it can doWhat it costs
Build time (prerender)Once, during next build or on revalidationRead files, databases and APIs; produce HTML and an RSC payloadBuild time only; served from a cache or CDN
Server, per requestOn each request (or each cache miss)Read cookies, headers, search params and fresh dataServer compute and latency on every request
BrowserAfter the JavaScript loads, and on every interactionState, effects, event handlers, browser APIsDownload, parse and execute time on the user's device

Server Components can run in the first two places. Client Components run in all three: they are prerendered to HTML on the server for the first load, then hydrated and re-rendered in the browser.

Everything is a Server Component until you opt out

Components in the App Router are Server Components by default. They render on the server, can be async, can read data directly without an API layer, and send no JavaScript for themselves to the browser. You opt a module into the client with one directive:

"use client";
 
import { useState } from "react";
 
export function Counter() {
  const [n, setN] = useState(0);
  return <button onClick={() => setN(n + 1)}>{n}</button>;
}

The "use client" directive marks a boundary. That module, and every module it imports, becomes part of the client bundle. The rule we follow: keep "use client" on the smallest possible leaf. A button that needs state is a Client Component. The page that renders it is not.

The common mistake is putting "use client" at the top of a page or layout because something deep inside needs interactivity. That opts the whole subtree into the client bundle, including large libraries used only for rendering, like markdown parsers or date formatting. Push the directive down to the leaf and let the rest stay on the server.

What actually reaches the browser

The Next.js docs on Server and Client Components describe what happens on a first load:

  1. HTML shows a fast, non-interactive preview of the page.
  2. The RSC payload, a compact representation of the rendered Server Component tree with placeholders for Client Components, lets React reconcile the tree.
  3. JavaScript for Client Components hydrates them, attaching event handlers so they become interactive.

On later navigations, Next.js fetches only the RSC payload for the new route and renders Client Components entirely in the browser. That is why App Router navigations feel like a single-page app, even though most of the page was rendered on the server.

Server and client are not either/or

Server Components can render Client Components, and Client Components can receive server-rendered content through props, usually children. So a static article (server) can contain a small interactive widget (client), and an interactive wrapper (client) can hold server-rendered content without turning it into client code.

// app/docs/page.tsx (Server Component)
import { Tabs } from "./tabs"; // "use client"
import { getDocs } from "@/lib/docs";
 
export default async function DocsPage() {
  const docs = await getDocs();
  return (
    <Tabs labels={docs.map((d) => d.title)}>
      {docs.map((d) => (
        <article key={d.slug}>{d.body}</article> // still rendered on the server
      ))}
    </Tabs>
  );
}

The constraint to remember: a Client Component cannot import a Server Component, but it can render one that a server parent passed in. This is also how context providers work. The provider is a Client Component, but it wraps server-rendered children rather than converting them.

The picture to keep in your head: the server renders the page and hands the browser a few interactive islands in a sea of static HTML. For how data flows into those Server Components, see data fetching patterns in React Server Components.

Keep server code on the server

Anything passed from a Server Component to a Client Component as props is serialized into the page. Pass only the fields the UI needs. For modules that must never run in the browser, like database clients or code that reads secrets, add import "server-only" at the top so the build fails if one is ever imported into client code.

Server or client: how to decide

When you are unsure which side a component belongs on, ask what it needs, not what it looks like.

The component needs to...Make it aWhy
Read from a database, file system or private APIServer ComponentKeeps credentials and queries off the client
Render content that does not change after loadServer ComponentNo JavaScript shipped for it
Use large rendering-only libraries (markdown, syntax highlighting, date formatting)Server ComponentThe library never reaches the bundle
Hold state, respond to clicks or typingClient ComponentNeeds event handlers and React state
Use effects or browser APIs (window, localStorage, observers)Client ComponentOnly exists in the browser
Provide React context to its childrenClient Component, wrapping server childrenContext is a client feature, but its children can stay server-rendered

If a component needs things from both columns, split it. The server part fetches and formats, then passes plain data to a small client part that handles the interaction. That split is almost always simpler to test, too.

The static-to-dynamic spectrum

Separately from where code runs is when it runs. Next.js now treats this as a spectrum at the component level, not a switch for the whole route.

What makes something dynamic

Reading request-time information during render:

  • cookies() or headers()
  • searchParams
  • Route params that were not generated ahead of time with generateStaticParams
  • Data that is not cached

Everything else, including pure computation, module imports and cached data, can be prerendered.

Two models in Next.js 16

Without Cache Components (the long-standing default), the decision is made per route. If anything in the render reads request data, the whole route renders on every request. If nothing does, the route is prerendered at build time.

With Cache Components (cacheComponents: true), the decision is made per component. Next.js prerenders a static shell from everything it can, including content marked "use cache" and the fallbacks of Suspense boundaries, then streams the dynamic parts at request time. That is Partial Prerendering, and in Next.js 16 it is the default behaviour under Cache Components. Components that read request data must sit inside Suspense or be cached; otherwise the build tells you.

import { Suspense } from "react";
 
export default function ProductPage() {
  return (
    <>
      <ProductDetails /> {/* cached with "use cache": in the static shell */}
      <Suspense fallback={<CartSkeleton />}>
        <Cart /> {/* reads cookies: streamed at request time */}
      </Suspense>
    </>
  );
}

Keeping content routes fully static

For a marketing site or a content-heavy app, you want every route prerendered:

  • No request-time APIs in the render path.
  • Data read at build time from local files or a cached source.
  • generateStaticParams for dynamic segments, so each one is prerendered.
export async function generateStaticParams() {
  return posts.map((post) => ({ slug: post.slug }));
}
 
// Slugs not returned above respond with a 404 instead of rendering on demand.
export const dynamicParams = false;

dynamicParams belongs to the model without Cache Components. With cacheComponents: true the option is not available, so return notFound() from the page when a slug does not match anything.

For a content site, the fully static end of the spectrum often goes further than people expect: our guide to shipping fast without a database shows how far it takes you.

Streaming: send what you have, when you have it

Dynamic does not have to mean slow. With streaming, the server sends HTML in chunks: the shell and anything ready goes first, and each Suspense boundary fills in as its data resolves. A loading.tsx file is a shortcut that wraps a whole route segment in a Suspense boundary.

Place boundaries around the parts that are slow and independent, not around everything. Too few and one slow query holds up the page. Too many and the page pops in piece by piece, which looks broken and can cause layout shift if the fallbacks are not sized like the content.

Read the build output

When next build finishes, the route summary tells you what actually happened. ○ marks a static route, ƒ a route rendered on demand, and with Cache Components ◐ marks a partially prerendered route with a static shell and streamed dynamic content.

If a page you expected to be static shows up as dynamic, something on it read request data. Track it down rather than shrugging: one cookies() call inside a shared header component can make an entire section of the site dynamic. When we take over an existing Next.js codebase, this is one of the first reports we read.

Caching is the other half

Rendering decides where and when your code runs. Caching decides how often it has to. The two interact constantly, and most "stale data" and "why is this slow" problems live at that seam. We wrote a separate guide on Next.js caching because it deserves the space. The short version: cache deliberately at the data or component level, and invalidate by tag when the data changes.

Where the server runs matters too. Dynamic sections should render close to your database, while the static shell comes from a CDN close to the user. Our post on edge vs server rendering covers that trade-off.

Why this matters for performance

Prerendered routes have no render cost on the request path and can be served straight from a CDN, which helps time to first byte and Largest Contentful Paint. Small client islands mean less JavaScript to download, parse and hydrate, which keeps the main thread free and Interaction to Next Paint low. Our Core Web Vitals checklist shows how these choices map to the metrics Google measures, and where those prerendered routes are served from is a hosting decision we compare in the best hosting for Next.js.

Every kilobyte you keep on the server is a kilobyte the browser never downloads, parses or executes. On mobile, where CPU is usually the bottleneck, that is the difference between a page that feels instant and one that stutters on the first tap. When we speed-tested the Forbes Cloud 100 homepages, the median one shipped 2.0 MB of JavaScript to an emulated mid-range phone.

Common mistakes

  • "use client" on pages and layouts instead of leaves.
  • Fetching in useEffect data that a Server Component could load before the HTML is sent.
  • Reading cookies in a shared component and turning every page that uses it dynamic.
  • One Suspense boundary around the whole page, so the slowest query decides when anything appears.
  • Passing whole database records to Client Components, leaking fields into the page payload.
  • Assuming Client Components only render in the browser, then crashing on window during server rendering.

If you are moving an older app over and seeing these patterns, our guide to migrating to the App Router covers how to untangle them route by route.

The short version

Let the server do the heavy lifting. Put "use client" only on the leaves that genuinely need the browser. Keep routes static unless a real request-time need forces otherwise, stream the parts that must be fresh, and check the build output to confirm what you think is happening.

If you want a team that works this way by default on your next build, or a second pair of eyes on an app that has drifted, that is what our Next.js development work is for. Get in touch.

FAQ · 05 questions

Frequently asked questions

Are Client Components rendered on the server in Next.js?

Yes, on the first page load. Next.js prerenders Client Components to HTML on the server so the user sees content immediately, then sends their JavaScript to the browser to hydrate them and make them interactive. On later client-side navigations they render in the browser.

What makes a Next.js route dynamic instead of static?

Reading request-time information during render: cookies, headers, searchParams, uncached data, or route params that were not generated ahead of time. Without Cache Components, any of these makes the whole route render per request. With Cache Components, the static parts are still prerendered into a shell and only the sections that need request data render at request time.

What is Partial Prerendering in Next.js?

Partial Prerendering prerenders a static shell of a route, including any cached content and Suspense fallbacks, and streams the dynamic parts into it at request time. In Next.js 16 it is the default behaviour when Cache Components is enabled, replacing the earlier experimental ppr flag.

Can a Server Component be a child of a Client Component?

Yes, if it is passed in as a prop, usually children. A Client Component cannot import a Server Component directly, but a Server Component parent can render a Client Component and pass server-rendered content into it. That pattern is how providers and interactive wrappers stay on the client without dragging their contents along.

Does 'use client' make my whole app a single-page app?

No. 'use client' marks a boundary for one module and the modules it imports. Everything above that boundary stays on the server. You only get single-page-app behaviour if you put the directive at the top of the tree, which is the mistake to avoid.

Related service

Next.js Development Services

Production Next.js apps and sites, tuned for speed and search.

Learn more

Next step

Want this built right?

This is the work we do every day. Tell us what you are building and we will show you exactly how we would ship it.

First reply
Within 1 business day
Typical start
1–2 weeks
Pricing
Fixed price per phase
You own
All code and accounts