Hydration
The client-side process of attaching JavaScript event listeners and component state to server-rendered HTML so the page becomes interactive
Table of Contents
Structure Diagram
What is Hydration?
The client-side process of attaching JavaScript event listeners and component state to server-rendered HTML so the page becomes interactive. It is a core concept in Rendering & Frontend within Web Dev.
Core Principles
Server-rendered HTML (from SSR or SSG) gives users fast visual feedback, but it starts as inert markup. Hydration is the process where client-side JavaScript boots up, walks the existing server-generated DOM without recreating it from scratch, and attaches event listeners and reactive component state.
Between First Contentful Paint and the end of hydration sits the "uncanny valley": the UI looks ready, yet clicks and form inputs appear frozen until the main thread finishes hydrating.
Practical Takeaways
- Eliminate hydration mismatches: Nondeterministic values during initial render (
Date.now(),Math.random(), locale formatting, orwindowchecks) cause server and client trees to diverge, forcing expensive DOM tear-downs and UI flickers. Defer browser-only state touseEffect. - Shrink the hydration footprint: Hydrating a massive page monolith blocks the main thread and degrades INP. Use React Server Components, Selective Hydration with
<Suspense>, or Islands Architecture so non-interactive markup ships zero JS. - Defer below-the-fold widgets: Heavy charts or comment sections can hydrate lazily on viewport intersection or first interaction.
Notable Examples
- Next.js, Nuxt, and SvelteKit: Deliver server HTML for instant paint, then hydrate into a full client-side routed experience.
- React 18 Selective Hydration: Prioritizes hydrating the exact
<Suspense>boundary the user clicks first, even while other chunks are still streaming. - Astro Islands: Keeps static prose at 0 KB of JavaScript and hydrates only interactive islands like carousels or search modals.