Performance: Server and client component composition
HIGH IMPACT
This affects the initial page load speed and interactivity by deciding what renders on the server versus the client.
import Counter from './CounterClient'; export default function Page() { return ( <div> <h1>Welcome to the site</h1> <Counter /> </div> ); } // CounterClient.jsx 'use client'; import React from 'react'; export default function Counter() { const [count, setCount] = React.useState(0); return <button onClick={() => setCount(count + 1)}>Clicked {count} times</button>; }
'use client'; import React from 'react'; export default function Page() { const [count, setCount] = React.useState(0); return ( <div> <h1>Welcome to the site</h1> <button onClick={() => setCount(count + 1)}>Clicked {count} times</button> </div> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| All client component | High (full DOM built on client) | Multiple reflows during hydration | High paint cost due to delayed HTML | [X] Bad |
| Server component with client child | Low (static DOM from server) | Single reflow on initial load | Low paint cost, fast HTML paint | [OK] Good |