Passing data across boundaries
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
- Project a safe prop object
- Avoid importing server-only modules
lib/public-book.ts — complete projection helper
export type PublicBook = { slug: string; title: string; price: number; cover: string; description: string };export type BookRow = PublicBook & { internalNote: string };export function toPublicBook(row: BookRow): PublicBook { return { slug: row.slug, title: row.title, price: row.price, cover: row.cover, description: row.description };}The resulting object contains exactly slug, title, price, cover and description. The internalNote never becomes a property of that object.
How it works
Use an explicit projection instead of forwarding an entire database-like record. TypeScript types do not remove properties at runtime. React serialization is not identical to JSON: supported values include some additional types, and Server Functions are a special case, but arbitrary functions and class instances are not generally valid boundary props. A server-rendered child can be passed as a composition slot rather than imported by a client module. server-only guards import direction, not the contents of a serialized prop.
Server page fragment — send only what is needed
import Quantity from "../Quantity";export function Actions({ book }: { book: { title: string; internalNote: string } }) { return <Quantity title={book.title} />;}Quantity receives only the title. No internalNote is supplied to the client component.
Common mistake
const publicBook: PublicBook = row changes the static type but can preserve extra runtime fields. Use an explicit new object. Avoid passing private values even when the receiving component does not visibly display them.
Try it yourself
Given a record with title, price and internalNote, return only title and price. Inspect object keys and verify that the input was not modified. The companion JavaScript assessment tests projection, not RSC transport.
Further reading
Next lesson: Catalog project route map.