Performance: When to keep components on server
HIGH IMPACT
This affects the page load speed and interaction responsiveness by controlling what renders on the server versus the client.
export const dynamic = 'force-static'; export default async function DataComponent() { const res = await fetch('https://example.com/api/data'); const data = await res.json(); return <div>{data.content}</div>; }
import React from 'react'; export default function DataComponent() { const [data, setData] = React.useState(null); React.useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); if (!data) return <p>Loading...</p>; return <div>{data.content}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side data fetching component | High (many nodes created after JS loads) | Multiple reflows during hydration | High paint cost due to delayed content | [X] Bad |
| Server-rendered component with data | Low (HTML sent ready) | Single reflow on initial paint | Low paint cost, fast content display | [OK] Good |