Skip to content
SPURT.

Engineering

Next.js App Router in production: lessons from our client builds

Lessons from five Next.js App Router builds, from an artist portfolio to a retail POS: rendering, hydration, animations, config and testing.

By , Engineering

Published · 7 min read

In this article · 11
  1. Which builds are these lessons from?
  2. Where should ’use client’ go?
  3. What happens if you wrap a layout in ssr: false?
  4. How do you use localStorage without hydration errors?
  5. Do entrance animations hurt performance?
  6. Why pin exact versions for client-only libraries?
  7. How do you run Next.js on a shop counter?
  8. Where should business logic live?
  9. What does "done" mean on a larger build?
  10. What do we do by default now?
  11. Sources

Short answer Keep pages as Server Components and push 'use client' down to the smallest interactive piece. Never wrap a layout in ssr: false. Treat saved browser state and entrance animations as hydration and LCP hazards. Pin exact versions for workers and native modules, and pin the workspace root in monorepos. Each lesson below came from a real build.

Our old version of this post claimed lessons from "20+ projects". That wasn't a number we could stand behind, so this rewrite sticks to five App Router codebases we can open and point at.

Which builds are these lessons from?

BuildNext.js versionBuiltWhat it is
B.S. Desai14.2Dec 2025 to Apr 2026Bilingual artist portfolio with a WhatsApp enquiry cart and a catalogue flipbook
FlyHigh Pre School14.2Apr to May 2026Ten-page admissions site with video, motion and structured data
A temple management system16.1Mar to Jul 2026Counter billing, donations with PDF receipts, inventory, expenses, reports
A retail point of sale16.3Aug 2026 onward, in developmentOffline-first till app and cloud owner dashboard in a pnpm monorepo
This website15.5Jul to Sep 2026Statically generated marketing site and blog

Our previous studio site, on Next.js 16.1, supplied the most expensive lesson, so it's in here too.

Where should 'use client' go?

On the smallest thing that needs the browser. Not on the page.

On B.S. Desai we marked most page files 'use client', including the artwork detail page, because they read from client-side stores for the cart and the language toggle. A client page can't export metadata or generateMetadata. The result, checked on 29 September 2026: /gallery, /about, /exhibitions and /gallery/1 all share the same title tag. Twenty-one artworks, one title.

Four months later on Fly High we split routes into a server page.tsx, which exports its own metadata and canonical URL, and a client component for the interactive parts, such as ContactPageClient.tsx. The pattern we use now:

tsx
// app/gallery/[id]/page.tsx: a Server Component
import { artworks } from '@/data/artworks'
import EnquiryButton from './EnquiryButton' // 'use client', the only interactive part

export const dynamicParams = false
export const generateStaticParams = () => artworks.map((a) => ({ id: a.id }))

type Props = { params: Promise<{ id: string }> }

export async function generateMetadata({ params }: Props) {
  const { id } = await params
  const art = artworks.find((a) => a.id === id)
  return { title: art ? `${art.title} by B.S. Desai` : 'Artwork' }
}

export default async function ArtworkPage({ params }: Props) {
  const { id } = await params
  const art = artworks.find((a) => a.id === id)!
  return (
    <article>
      <h1>{art.title}</h1>
      <EnquiryButton id={art.id} />
    </article>
  )
}

(params is a Promise from Next.js 15. On 14, it's a plain object.)

What happens if you wrap a layout in ssr: false?

Everything inside it disappears from the HTML. On our previous studio site, a provider loaded with next/dynamic and ssr: false wrapped the whole layout. Browsers and Google rendered it fine. AI crawlers, which don't run JavaScript, received a page with zero words and no H1 for more than five months. We wrote up the details in why ChatGPT couldn't read our website.

ssr: false is fine at the leaves. B.S. Desai's exhibition flipbook uses it correctly: PDF rendering needs browser APIs, and the component has no children. This site's hero particle canvas uses it the same way.

How do you use localStorage without hydration errors?

B.S. Desai's enquiry cart is a Zustand store persisted to localStorage, so a visitor's picks survive a refresh. The server can't see localStorage, so it renders an empty cart, while the browser renders three items. React flags the mismatch.

The fix is to render the server's version first and switch after mount:

tsx
'use client'
import { useEffect, useState } from 'react'

export function useHasMounted() {
  const [mounted, setMounted] = useState(false)
  useEffect(() => setMounted(true), [])
  return mounted
}

// in the navbar: the badge appears after hydration
const mounted = useHasMounted()
{mounted && cart.length > 0 && <span className="badge">{cart.length}</span>}

That's right for a cart badge. It's wrong for content. The same site's English and Kannada toggle lives in client state, so the Kannada text never has a URL of its own and crawlers only ever see English. Google recommends "different URLs for each language version of a page" rather than cookies or browser settings (Google: multilingual sites). If a second language matters for search, give it routes, like /kn/gallery.

Do entrance animations hurt performance?

They hurt Largest Contentful Paint, because the browser doesn't count an element with opacity: 0 as painted. Fly High wraps every page in a Framer Motion transition that starts at opacity: 0 in the server HTML, and B.S. Desai fades in its H1. In our Lighthouse runs, their LCPs were 3.3 and 4.7 seconds, with most of the time spent waiting for JavaScript (measurements and method).

The rule we follow now: the largest thing on the first screen starts visible. Animate its position or scale if you must, never its opacity from zero. And respect prefers-reduced-motion. Fly High's transition wrapper already skips the animation for visitors who ask for less motion.

Why pin exact versions for client-only libraries?

B.S. Desai's flipbook renders PDFs with react-pdf, which runs PDF.js in a web worker loaded from a URL. The worker URL named version 3.11.174, while package.json allowed ^3.11.174. When the installed library and the worker drifted apart, the flipbook broke. The April 2026 fix was two changes: exact versions in package.json, and a worker URL built from pdfjs.version so the two can never disagree.

Anything loaded at runtime from outside your bundle, such as workers, WebAssembly or CDN scripts, should be pinned to the exact version your code was built against.

How do you run Next.js on a shop counter?

The retail point of sale runs its till app on the shop's own Windows computer, and it has to keep billing when the internet drops. Most of what made that work was configuration:

ts
// apps/pos/next.config.ts
import path from 'node:path'
import type { NextConfig } from 'next'

const workspaceRoot = path.join(import.meta.dirname, '../../')

const nextConfig: NextConfig = {
  output: 'standalone',                               // ship `node server.js` to the till
  outputFileTracingRoot: workspaceRoot,               // pin the monorepo root for builds...
  turbopack: { root: workspaceRoot },                 // ...and for the dev watcher
  serverExternalPackages: ['better-sqlite3', 'pino'], // native or self-resolving: don't bundle
  transpilePackages: ['@pos/db', '@pos/domain'],      // workspace packages ship TypeScript
}

export default nextConfig

The two root settings came from an incident. A stray lockfile in a developer's home folder made Next.js decide the home folder was the project root. Turbopack's dev watcher then crawled every file under it, pegging CPU and memory on the development machine. Pinning the root explicitly fixed it regardless of what else sits on the disk.

Where should business logic live?

In the database transaction, not in React. The temple management system handles money at a counter, so:

  • Money is stored as integer paise, never as floating-point rupees.
  • Receipt numbers are generated inside the same transaction as the sale, with a SELECT … FOR UPDATE lock, so two counters can't issue the same number.
  • Every route handler checks auth and validates input with Zod before touching the database.
  • Donation receipts are generated as PDFs on the server, so the browser never assembles an official document.
  • Voids are soft deletes with a mandatory reason, which keeps an audit trail.

None of this is specific to Next.js. The App Router just makes it easy to keep this code on the server, where it belongs. It's the approach we bring to custom software generally.

What does "done" mean on a larger build?

The retail POS keeps one status file, and it is the only document in the repository allowed to say a feature works. On 18 September 2026 its test suite passed 1,376 tests, and the status file still said plainly that none of the newest features had been used by a person at a counter. The integration pass found services that had been written but were never called, which is invisible to a test suite that only tests them in isolation.

It also found that local browser tests had been passing only because a git-ignored .env.local set a branch ID that didn't match the test data. CI failed the same tests four times. Two habits came out of that: CI is the source of truth, and "built" and "works" are different words.

What do we do by default now?

  1. Pages are Server Components. 'use client' goes on leaves.
  2. No ssr: false on anything that takes children.
  3. generateStaticParams, dynamicParams = false and generateMetadata on every content route.
  4. The first screen paints without JavaScript.
  5. Browser-saved state only for badges and preferences, never for content.
  6. Exact versions for anything loaded at runtime.
  7. curl every template before calling a deploy done.

If you're planning a Next.js build, this is how our web development team works.

Sources

Frequently asked questions

Should every page in the Next.js App Router be a Server Component?

Every page file, yes, in almost all cases. A server page can export generateMetadata, fetch data without shipping it to the browser, and render its text into HTML. Put 'use client' on the smallest interactive piece inside it, such as a button, a form or a carousel, rather than on the page. Marking a whole page as a client component loses per-page metadata.

How do I fix hydration errors caused by localStorage in Next.js?

The server can't read localStorage, so it renders the default state while the browser renders the saved one, and React reports a mismatch. Render the default on both, then show the saved state after the component mounts. A small useHasMounted hook does it. Keep this pattern to badges and counters, never to the main content crawlers should read.

Can a Next.js app run offline on a shop's own computer?

Yes. Build with output set to 'standalone' and Next.js produces a self-contained server you start with node server.js, no internet required. Pair it with a local database such as SQLite and sync to the cloud in the background. Native modules like better-sqlite3 must be listed in serverExternalPackages so they aren't bundled.

Is the Next.js App Router ready for production?

In our experience, yes. We've built on it since Next.js 14.2: marketing sites, an artist's portfolio, a temple management system and a retail point of sale. The problems we hit were almost all our own: client components placed too high in the tree, animations hiding content, loose version ranges and unpinned monorepo roots.

Start a project

Tell us what you’re building. One of the founders — not a sales team — comes back with questions, a plan and a fixed quote.