Automatic Code Elimination in Server Components
What you'll learn: How React Server Components automatically keep server-only dependencies out of your client JavaScript bundle.
The Bundle Weight Problem — Solved Automatically
When you import a library in a Server Component, that code never ships to the browser. React's build tooling analyzes your component tree and eliminates any code that only runs on the server from the client-side JavaScript bundle.
This is fundamentally different from traditional React apps, where every import adds weight to what users download.
How It Works
Remember: Server Components run once on the server and send only the rendered output (that special RSC wire format, not HTML). Since these components never execute in the browser, React's bundler can confidently strip out all their dependencies.
// ProductList.server.tsx
import { db } from './database'; // ← NEVER sent to client
import { formatCurrency } from 'huge-formatting-library'; // ← Also eliminated
export default async function ProductList() {
const products = await db.query('SELECT * FROM products');
return products.map(p => (
<div key={p.id}>
{p.name}: {formatCurrency(p.price)}
</div>
));
}
That huge-formatting-library? Could be 500KB. Doesn't matter — your users never download it.
The Analogy
Think of a restaurant kitchen versus the dining room. All the industrial equipment, ingredient suppliers, and prep tools (server dependencies) stay in the kitchen. Customers only receive the finished dish (rendered output). They don't need to carry a portable stove home to enjoy their meal.
Key Takeaway: Server Component imports are automatically eliminated from client bundles, letting you use any library—no matter how large—without impacting user download times or browser performance.