
Oct 27, 2023
Available for senior roles & selected contracts — email me
Hydration is one of those React concepts that sounds more complicated than it is. If you've ever wondered how a static HTML page turns into a fully interactive React app, hydration is the answer.
Hydration is the process of taking server-rendered static HTML and attaching React to it so it becomes interactive. The HTML is already there on the page; hydration wires up the event handlers and state so the markup actually does something when you click it.
With server-side rendering (SSR), your server sends a fully formed HTML page. That's great for first paint and SEO, but on its own it's static. Nothing responds to clicks, nothing updates. Hydration is the step that attaches the event handlers and React state to that markup and makes the page interactive.
Here's what actually happens:
Hydration is not always smooth. The most common issue is the 'Text content did not match' error, which happens when your server-rendered content doesn't match what React produces on the client during hydration. The two have to line up.
A few things that help keep hydration clean:
Newer versions of React support streaming SSR and selective hydration. Instead of hydrating the whole page at once, React can prioritise and hydrate different parts of the app as needed, which makes large pages feel responsive sooner.
Hydration is the bridge between static server-rendered content and the interactive app the user ends up with. Understanding how it works makes a lot of SSR behaviour and errors much easier to reason about.
Exploring the differences between these essential testing approaches