Hydration Proof

Search documentation

Find a page or section

Prove the cause of a hydration mismatch

Reload the page with one thing changed, and see which change moves the value.

Use probes to prove the cause of a hydration mismatch. With --probe, hydration-proof reloads the affected page while changing one browser setting at a time. If the finding changes with that setting, the report names it as the cause.

Turn probes on

npx hydration-proof test --probe

You can also enable probes in the config with probes: true, or choose factors:

hydration-proof.config.ts
import { defineConfig } from "hydration-proof";
 
export default defineConfig({
  probes: { factors: ["time", "random"], maxPages: 5 },
});

Probes are off by default because each factor needs another page load.

How to prove the cause of a hydration mismatch

A regular finding suggests a likely cause based on its values and context. A probe tests that suggestion:

  1. The page is loaded with the browser clock and Math.random() fixed.
  2. It is loaded again, identically. This is the control.
  3. It is loaded once more for each factor, with only that factor changed.
  4. hydration-proof compares the finding across the loads.
FactorWhat changesProves
timeThe browser clock moves by 3 days, 7 hours, 11 minutes and 13 secondsTime-dependent value
randomA different seed for Math.random() and crypto.getRandomValues()Random value
localeThe browser locale becomes the server's (or another one)Locale-dependent formatting
timezoneThe browser timezone becomes the server's (or another one)Timezone difference
themeLight ↔ darkTheme preference
viewportDesktop ↔ mobileScreen size or media query
storageNo localStorage, sessionStorage or storageState from the scenario (only when it has them)Browser storage

The time probe moves the clock by an unusual amount so changes to a date or time are easier to spot.

Proven or likely?

When changing one factor changes or removes a finding, the terminal marks that cause as proven:

    HP1001 Text differs between server and client  (timezone difference, proven)
      #last-login  in LastLogin
      server: "Signed in at 5:00 AM"
      client: "Signed in at 10:00 AM"
 
  Probes
    HP1001 /dashboard #last-login  proven: timezone difference

The report also shows what changed and puts the proven cause's fixes first.

If several factors affect the finding, the report lists them. It also notes which factors made no difference.

What if an identical reload renders differently?

Look for changing server or API data. When identical loads disagree, the other probes cannot isolate a cause reliably. See server and client data.

What do probes cost?

Probes run only for value mismatches: text, attributes, styles, classes, dangerouslySetInnerHTML, and form state (HP1001 to HP1006, HP1012 and HP1013). Ignored, suppressed and info findings are skipped.

  • Each probed page costs up to 9 extra page loads: the fixed load, the control, and one per factor.
  • maxPages (default 5) caps the pages probed per run. Pages with the most errors go first, and a note says how many were left out.
  • The run ends with a note of how many extra loads the probes took.

If you already suspect a cause, narrow factors to save page loads.

Probes never hide a finding

Probes change the test browser, not the server. A fixed browser clock makes loads comparable; it does not stop the check from finding a server/client difference. The clock and randomSeed scenario options work the same way.

Options

OptionTypeDefaultDescription
factorsProbeFactor[]all that applyWhat to vary.
maxPagesnumber5Most pages probed per run.