Performance: Client component boundaries
HIGH IMPACT
This affects how much JavaScript is sent to the browser and how fast the page becomes interactive.
import React from 'react'; import Counter from './Counter'; export default function Page() { return ( <div> <h1>Welcome</h1> <Counter /> <p>Static content here</p> </div> ); } // Counter.tsx 'use client'; import React from 'react'; function Counter() { const [count, setCount] = React.useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; } export default Counter;
'use client'; import React from 'react'; export default function Page() { // Entire page is a client component const [count, setCount] = React.useState(0); return ( <div> <h1>Welcome</h1> <button onClick={() => setCount(count + 1)}>Count: {count}</button> <p>Static content here</p> </div> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Whole page as client component | High (all nodes hydrated) | Multiple reflows during hydration | High paint cost due to JS execution | [X] Bad |
| Small isolated client components | Low (only interactive parts hydrated) | Single reflow per component | Lower paint cost, faster interaction | [OK] Good |