Question presented to candidate: "Users report a flash of different content and the console says hydration failed. What is hydration, what causes this error, and how do you fix it without hiding the bug?"
What a strong answer should cover:
- Hydration is React attaching state and event handlers to HTML that the server already rendered, reusing the DOM instead of recreating it.
- The first client render must produce exactly the same output as the server render; any difference is a mismatch.
- Common causes: time and random values,
typeof windowbranches, locale formatting, invalid HTML nesting, browser extensions changing the DOM. - On a mismatch React 19 discards the server HTML for that tree and re-renders on the client, which is slower and can flash.
- Fixes: render the same value first and change it in an effect, use
suppressHydrationWarningonly for known cases such as timestamps, fix invalid nesting.
Clarifying questions expected:
- "Does it happen for every user or only some?" β only some usually means extensions, locales or time zones.
- "Is the mismatched value needed for the first paint?" β if not, render it after mount.
Code / implementation expected: Yes β a component that mismatches, and the corrected version.