Server Components by default
Scope: Next.js 16.x candidate, App Router, Cache Components disabled, TypeScript. Source walkthroughs and expected outcomes; no framework build or browser execution has been verified.
What you will learn
- Identify server-only work
- Select safe data to render
lib/books.ts — server data module
import 'server-only';import { toPublicBook, type BookRow } from './public-book';const rows: BookRow[] = [ { slug: 'moss', title: 'Moss Garden', price: 18, cover: '/covers/moss.png', description: 'A guide to small green spaces.', internalNote: 'SYNTHETIC-INTERNAL-MOSS' }, { slug: 'tide', title: 'Tide Notes', price: 12, cover: '/covers/tide.png', description: 'A journal of coastal walks.', internalNote: 'SYNTHETIC-INTERNAL-TIDE' }, { slug: 'fern', title: 'Fern Field', price: 15, cover: '/covers/fern.png', description: 'A field guide to ferns.', internalNote: 'SYNTHETIC-INTERNAL-FERN' }];export function getBooks() { return rows.map(toPublicBook); }export function getBook(slug: string) { const row = rows.find(b => b.slug === slug); return row ? toPublicBook(row) : undefined; }getBooks returns three public book records with the internalNote omitted; no external data connection exists.
How it works
Server Components can use asynchronous reads, but that does not mean they run for every request. Depending on rendering and caching settings, work can happen at build time or request time. A page is not automatically an API endpoint. Server code should expose only data needed by the UI. The fixture uses a local array and explicit projection instead of a database, so learners can understand the boundary first.
app/catalog/page.tsx — smaller standalone route variant
import { getBooks } from "../../lib/books";export default function Catalog() { const books = getBooks(); return <><h1>Catalog</h1><ul>{books.map(book => <li key={book.slug}>{book.title}</li>)}</ul></>;}The server prepares the list, which shows Moss Garden, Tide Notes and Fern Field in fixture order.
Common mistake
Do not add use server to a normal page to make it a Server Component. That directive concerns Server Functions, a different interface covered later. Also avoid claiming that a server-rendered value is automatically private once included in UI or props.
Try it yourself
List the operations that need a server boundary (reading a private store, projecting fields) versus the user interactions that need a client component (changing an on-screen quantity).
Further reading
Next lesson: Client boundary and state.