Performance: What can run in server components
HIGH IMPACT
This affects the initial page load speed and server response time by offloading work from the client to the server.
export default async function Page() { const res = await fetch('https://api.example.com/data'); const data = await res.json(); return <div>{data.map(item => <p key={item.id}>{item.name}</p>)}</div>; }
'use client' import { useState, useEffect } from 'react'; export default function Page() { const [data, setData] = useState([]); useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); return <ClientComponent data={data} />; } function ClientComponent({ data }) { return <div>{data.map(item => <p key={item.id}>{item.name}</p>)}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side data fetching and rendering | Many DOM nodes created on client | Multiple reflows during hydration | High paint cost due to delayed content | [X] Bad |
| Server component rendering with data fetching | DOM nodes sent pre-built | Single reflow on initial paint | Low paint cost with immediate content | [OK] Good |