A commerce demo for exploring Cache Components, Partial Prefetching, and static guarantees in Next.js.
This repository started as the demo for my talk, Composition, Caching, and Architecture in Modern Next.js. Since then, the current app has moved to the latest Next.js canary and follows the architecture from the Next.js App Architecture skill and Component Architecture for React Server Components.
- Cache Components mix static, cached, and request-time content in the same route. Shared product data uses
'use cache', while cookie-backed cart and saved state use'use cache: private'. - Partial Prefetching prefetches the shared route shell. Product links use
prefetch={true}so cached product details are available before navigation, while personalized state waits for the visit. ensureStaticguarantees static output at the stage a route needs it. The store layout guarantees its shell, product routes guarantee each prefetch, and the About page guarantees a full navigation.- Server Functions update the cart, saved products, account details, and featured products on the server, then invalidate only the cache tags they change with
updateTag. - React Compiler memoizes components and hooks automatically, so the code needs no manual
useMemooruseCallback. - View Transitions animate personalized content as it streams in from Suspense.
- Async React keeps the interface responsive during server work with
Suspense,useOptimistic,useTransition, anduse.
starteris the intentionally unoptimized starting point used during the talk.route-groupseparates static and personalized routes with route groups.request-contextencodes request context in the route instead.legacy-talk-demopreserves the demo before the later cart and Next.js 16.4 work.
The main branch is the current version and continues to evolve with Next.js.
The app runs on Postgres. Copy .env.sample to .env.local, set DATABASE_URL, then:
pnpm install
pnpm run prisma.push
pnpm run prisma.seed
pnpm run devOpen http://localhost:3000 in your browser. You can inspect the database with pnpm run prisma.studio.
Run `main` locally with SQLite
Change the datasource provider in prisma/schema.prisma from postgresql to sqlite, then add this to .env.local:
DATABASE_URL="file:./dev.db"Generate the SQLite client and create the local database:
pnpm exec prisma generate
pnpm run prisma.push
pnpm run prisma.seedThe schema and application code otherwise stay the same.
The end-to-end tests use @next/playwright with the instant() API to verify the static shell, product prefetches, and personalized state across navigations.
pnpm test:e2eStatic checks:
pnpm lint
pnpm exec tsc --noEmit- Next.js canary: App Router, Cache Components, Partial Prefetching,
ensureStatic, and Server Functions - React with React Compiler: Suspense, View Transitions,
useOptimistic, anduse - TypeScript and Tailwind CSS v4
- Prisma on PostgreSQL
- Ariakit for accessible dialogs and popovers
- Playwright with
@next/playwrightfor end-to-end tests