Next.jsMedium

What are common pitfalls when using the App Router?

The most common mistakes are client boundaries placed too high, misunderstanding caching (old defaults, per-user data in shared caches), request-time reads at the top of layouts, relying on Proxy or layouts for authorization, waterfalls from sequential awaits, hydration mismatches, and outdated APIs such as synchronous params, middleware.ts or one-argument revalidateTag.

Rendering and boundaries

  • "use client" in layouts or pages turns everything below into client code. Keep boundaries at the leaves and use the children pattern.
  • Importing server-only modules into client code. Guard with import "server-only".
  • Passing non-serializable props (functions, class instances) to Client Components.

Data and caching

  • Assuming fetch is cached. It has not been since Next.js 15. With Cache Components, nothing is cached without "use cache".
  • Caching per-user data under a shared key, leaking data between users. Pass user IDs as arguments or use "use cache: private".
  • Waterfalls: sequential awaits in one component; start requests in parallel or split into Suspense boundaries.
  • cookies() at the top of the root layout, making the whole app request-time.
  • useSearchParams without <Suspense>, breaking static rendering.
  • Mutating outside Server Functions without router.refresh(), then wondering why the UI is stale.

Security

  • Proxy-only auth and layout-only auth checks. Authorize in the data layer and in every Server Function.
  • Returning whole database rows to the client.

Routing

  • Parallel routes without default.tsx (build fails in 16).
  • redirect() inside try/catch swallowing the redirect.
  • Using next/router in the App Router.

Outdated patterns to update

Synchronous params/cookies(), middleware.ts, useFormState, priority on images, images.domains, experimental.ppr, unstable_noStore, export const runtime = "edge", and next lint.

Code example

tsx
1// Pitfall: waterfall + whole-app dynamic + client boundary too high
2// "use client"; // makes the entire layout client code
3// export default async function Layout({ children }) {
4// const user = await getUser((await cookies()).get("s")); // request-time at the root
5// const posts = await getPosts(); // waits for getUser first
6// const stats = await getStats(); // waits for getPosts
7// }
8
9// Better
10import { Suspense } from "react";
11import { UserMenu } from "./user-menu"; // reads cookies, streams
12
13export default function Layout({ children }: { children: React.ReactNode }) {
14 return (
15 <html lang="en">
16 <body>
17 <header>
18 Acme
19 <Suspense fallback={<span>…</span>}>
20 <UserMenu />
21 </Suspense>
22 </header>
23 {children}
24 </body>
25 </html>
26 );
27}
28
29// In pages: start independent requests together
30// const [posts, stats] = await Promise.all([getPosts(), getStats()]);

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app