Performance: React components in Astro
This affects page load speed and interaction responsiveness by how React components are loaded and hydrated within Astro pages.
--- import ReactComponent from './Component.jsx'; --- <ReactComponent client:idle />
--- import ReactComponent from './Component.jsx'; --- <ReactComponent client:load />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| client:load hydration | Multiple DOM updates during hydration | Triggers 1 reflow per component | Moderate paint cost | [X] Bad |
| client:idle hydration | DOM updates deferred until idle | Single reflow after idle | Lower paint cost | [OK] Good |
client:load to load components on the client after page load.client:load is the standard for React components to run in browser.--- import Counter from '../components/Counter.jsx'; ---
Counter is a React component that shows a button and a count starting at 0, which increments on click.client:load directive loads the React component in the browser, enabling interactivity.--- import MyButton from '../components/MyButton.jsx'; ---
MyButton is a React component that should be interactive on the client.client:server means the component runs only on the server, no client interactivity.client:load or similar client directives.client:load loads React on client, enabling data fetching and updates.Pass the test and this pattern moves unknown