Sub topic 8
What can cross the boundary: serializable props
This chapter assumes you know React props and JSX, useState, async/await, and the idea of a "use client" module boundary from the previous chapters. It also assumes you have seen a simplified RSC payload, where server output is a stream of rows that reference client components.
Why props must be serializable
A Server Component runs on the server. A Client Component runs in the browser. When a Server Component renders a Client Component, the props it passes have to travel from one machine to another, inside the RSC payload.
The payload is text. React must turn every prop into text on the server and rebuild the value in the browser. This process is called serialization. A value that React cannot rebuild on the other side cannot be a prop that crosses the boundary.
The rule applies at one specific place: where a Server Component renders an element whose type is a client reference. Props passed between two Server Components never leave the server. Props passed between two Client Components never leave the browser. Only the server-to-client edge is checked.
What you can pass
The exact list depends on your React version, so check the documentation for the version you use. The following types are supported in current React releases.
| Kind of value | Crosses the boundary? | Notes |
|---|---|---|
| string, number, boolean, null, undefined | Yes | Includes `NaN`, `Infinity`, `-0` and `bigint` in recent versions. |
| Plain objects and arrays | Yes | Every nested value must also be serializable. |
| `Date` | Yes | Arrives as a `Date`, not a string. |
| `Map`, `Set`, typed arrays, `ArrayBuffer` | Yes | In current versions. |
| `FormData` | Yes | Mostly useful for Server Functions. |
| Promises | Yes | The client can read them with `use`. |
| JSX elements | Yes | They are descriptions of UI, so they serialize as element rows. |
| Server Functions | Yes | Sent as a reference, not as code. |
| Plain functions and event handlers | No | Code cannot be sent as data. |
| Class instances | No | Methods and the prototype would be lost. |
| Symbols not registered globally | No | The identity would not survive. |
The two entries that surprise people are JSX and promises. JSX is allowed because an element is already a plain description: a type, a key and props. A promise is allowed because the payload can stream. The server sends a placeholder first. The client receives the resolved value in a later row.
What you cannot pass
The most common error is passing an event handler:
// app/page.js (Server Component)
import Button from './Button';
export default function Page() {
function handleClick() {
console.log('clicked');
}
// Error: functions cannot be passed directly to Client Components
return <Button onClick={handleClick} />;
}handleClick is a closure. It could capture variables that only exist on the server. React cannot ship the function body, so it refuses at render time and tells you which prop failed. The error message names the prop, such as onClick={function handleClick}.
The fix is to move the handler into the Client Component, where it belongs:
// app/Button.js
'use client';
export default function Button({ label }) {
return (
<button onClick={() => console.log('clicked')}>
{label}
</button>
);
}// app/page.js (Server Component)
import Button from './Button';
export default function Page() {
return <Button label="Click me" />;
}The server decides what to show. The client decides what happens on interaction. If the interaction must run server code, use a Server Function instead (see the exceptions below).
Class instances
Class instances fail for a related reason. The payload does not carry prototypes. Consider this server code:
// lib/money.js
export class Money {
constructor(amount, currency) {
this.amount = amount;
this.currency = currency;
}
format() {
return `${this.amount} ${this.currency}`;
}
}If a Server Component passes new Money(5, 'EUR') to a Client Component, React rejects it. Even if the fields were copied, format would be gone. Pass a plain object and rebuild the helper on the client if you need it:
// Server Component
<Price amount={5} currency="EUR" />// app/Price.js
'use client';
export default function Price({ amount, currency }) {
return <span>{new Intl.NumberFormat('en', { style: 'currency', currency }).format(amount)}</span>;
}Exceptions: functions that do cross
Two kinds of function can appear in props.
- Server Functions. A function exported from a
"use server"module is sent as a reference. The client calls it, and the call becomes a network request. The function body never reaches the browser. - Client references. A component imported from a
"use client"module is also a reference. You can pass it as a prop, for exampleicon={Icon}, as long as it is the imported reference and not a locally defined function.
// app/actions.js
'use server';
export async function like(id) {
// update the database
}// app/page.js (Server Component)
import LikeButton from './LikeButton';
import { like } from './actions';
export default function Page() {
return <LikeButton postId={42} onLike={like} />;
}A function defined inline inside a Server Component is not a Server Function unless it has its own "use server" directive in its body. Without it, React treats it as an ordinary function and rejects it.
What the payload looks like
You can see the difference between a value and a reference in the payload. This simplified example passes a number, a date, and a Server Function to a client component. The exact syntax differs between React versions and frameworks.
1:I["app/LikeButton.js",["chunk-like.js"],"default"]
2:{"id":"action-id","bound":null}
0:["$","$L1",null,{"postId":42,"created":"$D2026-12-02T09:11:30.111Z","onLike":"$F2"}]Reading row 0:
postIdis the plain JSON number42.createdis a string with a marker, here$D, that tells the client to rebuild aDate. Markers beginning with$encode the types that JSON cannot express.onLikeis a marker that points to a server reference. It contains an identifier, not code.
This is the reason a plain JSON round trip would not be enough. JSON.stringify turns a Date into a string and drops undefined and functions silently. The Flight format encodes these values explicitly so the client gets what the server meant.
Strings that begin with `$`
Because $ is the marker prefix, the serializer must escape a real string that starts with $. React does this for you. A prop value of "$5.00" is sent with an extra $ and decoded back to "$5.00". You never write escapes by hand, but you may notice doubled $ characters when you read a raw payload.
Shared references and cycles
If the same object appears twice in the props, the serializer can emit it once and refer to it by id. This keeps payloads smaller and keeps shared identity inside one payload. Do not rely on it across payloads. Each navigation produces a new payload, so object identity is not stable between them.
Edge cases and gotchas
- Passing a whole database row. A row from your ORM may be a class instance or contain extra fields. Fix both problems by selecting the fields you need and building a plain object. This also limits what you expose, which the security chapter returns to.
undefinedversus missing. Anundefinedprop survives asundefined. You do not need to filter it out.- Large props. Everything you pass is part of the payload. A 2 MB array passed to a Client Component adds 2 MB to the response. Pass only what the client renders or uses.
- Mutation after render. Changing an object after the server passed it has no effect on the client. The client holds a copy.
- Environment code in props. A value that depends on
process.envis read on the server. Only the resulting value crosses. This is useful, but it also means a secret placed in a prop is sent to the browser.
A debugging checklist
When you see a serialization error, work through these steps.
- Read the error and find the prop name it reports.
- Check whether the value is a function, a class instance or a symbol.
- If it is a handler, move it into the Client Component or replace it with a Server Function.
- If it is a class instance, convert it to a plain object at the boundary.
- If it is a large or sensitive object, pick the fields the client needs.
Exercise
A Server Component fetches a user with const user = await db.users.find(id), where user is an instance of a User class with a fullName() method and a private passwordHash field. It renders <Profile user={user} onSave={() => save(user.id)} /> and Profile is a Client Component. Name the two problems and give a fix for each.
Show answer
First, user is a class instance, so its prototype and fullName() method cannot be serialized. It also carries passwordHash, which would be sent to the browser. Fix it by passing a plain object with only the fields needed, such as { id, name }, and compute the full name on the server or in the client. Second, onSave is an inline function that closes over server data, and plain functions cannot cross the boundary. Fix it by exporting save from a "use server" module and passing that function, or by calling it from inside the Client Component. Because the function takes input from the network, it should validate its arguments.
Exercise
Which of these props can a Server Component pass to a Client Component? (a) new Date(), (b) a Map of ids to names, (c) a promise returned by fetch(...).then(r => r.json()), (d) Symbol('id'), (e) a JSX element such as <Comments /> where Comments is a Server Component.
Show answer
(a), (b), (c) and (e) can be passed in current React versions. A Date and a Map have serialization markers in the payload, a promise is sent as a placeholder that resolves in a later row, and a JSX element serializes as an element row, with the Server Component rendered on the server. (d) cannot be passed, because a local symbol has no identity on the other side.