Sub topic 2
What the Bundler and Framework Do
Assume you know React components, JSX, hooks, promises, and the difference between client-side and server-side rendering.
What the Bundler and Framework Do
A bundler analyzes imports and creates files the browser can load. In an RSC application, it builds separate graphs:
- The server graph contains Server Components and server-only dependencies.
- The client graph starts at modules marked with
"use client". - A manifest records each client module, its export, and the browser chunk that contains it.
The framework connects these graphs to requests and responses. It runs Server Components on the server, produces the RSC payload, sends the required client chunks, and lets the browser reconstruct the tree.
// Counter.jsx
'use client';
import { useState } from 'react';
export default function Counter({ initial }) {
const [count, setCount] = useState(initial);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}The "use client" line does not mean that every render happens only in the browser. It marks the module as the start of a client boundary. The component can use state and event handlers, so its code must be available to the browser.
Client References in the Payload
The server does not send the full JavaScript implementation of Counter inside the RSC payload. Instead, it sends a client reference: information that identifies the module and export. A simplified payload might contain:
1:I["./Counter.jsx",["chunk-counter.js"],"default"]
0:["$","$L1",null,{"initial":3}]Row 1 maps reference $L1 to the module and browser chunk. Row 0 uses $L1 in the element tree. The framework and bundler provide the exact format and loading logic.
Serializable Props
Props crossing a server-to-client boundary must be representable in the payload. Strings, numbers, booleans, null, arrays, plain objects, and supported framework values are common choices. A function created on the server cannot normally be sent as a prop because its executable closure cannot be serialized.
Validate data before exposing it. The payload can reveal values that the client receives, so do not pass database records or secrets unnecessarily.
Composing Server and Client Components
A Server Component can render a Client Component and pass serializable props. It can also pass server-rendered content as children:
// Modal.jsx
'use client';
import { useState } from 'react';
export default function Modal({ children }) {
const [open, setOpen] = useState(false);
return (
<>
<button onClick={() => setOpen(!open)}>Toggle</button>
{open && <div>{children}</div>}
</>
);
}This pattern keeps data-heavy content on the server while the client component controls interaction.
Exercise
Why does the RSC payload contain a reference to a Client Component instead of its complete implementation?
Show answer
The bundler puts the implementation in a browser chunk, while the payload identifies which module and export the client should load.