What Are Server Components?
React Server Components (RSC) let you write components that render exclusively on the server. They never ship JavaScript to the browser, resulting in dramatically smaller bundle sizes.
The Key Difference
// Server Component (default in Next.js App Router)
async function UserProfile({ id }) {
const user = await db.user.findById(id); // Direct DB access!
return <div>{user.name}</div>;
}
// Client Component (needs "use client" directive)
"use client";
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(c + 1)}>{count}</button>;
}
When to Use Server Components
- Data fetching β Access databases, APIs, file system directly
- Large dependencies β Keep heavy libraries off the client bundle
- Static content β Blog posts, documentation, product pages
- SEO-critical pages β Full HTML delivered on first paint
When to Use Client Components
- Interactivity β onClick, onChange, form inputs
- Browser APIs β localStorage, geolocation, Web Audio
- State management β useState, useReducer, context
- Effects β useEffect, subscriptions, timers
Performance Impact
In real-world Next.js apps, RSC typically reduces:
- JavaScript bundle size by 30-60%
- Time to Interactive (TTI) by 40-50%
- First Contentful Paint (FCP) by 20-30%
Best Practices
- Default to Server Components β Only add βuse clientβ when needed
- Push client boundaries down β Keep interactive parts as small leaves
- Use Suspense boundaries β Show loading states for async data
- Avoid prop serialization issues β Donβt pass functions from server to client
- Leverage streaming β Use loading.tsx for progressive rendering