The Real Fullstack

The Hydration Mismatch

The page looks right for half a second — then the greeting, the cart badge and the offer date all change. Why?

Ingénieur senior8 minLaboratoire de débogageDéfi de code
angularssrnextjslocalstorage

Ce défi n'est pas encore traduit en Français. Vous lisez la version anglaise.

Mission:Find why server HTML and client rendering disagree, and make the first client render match the server while still showing personal data.Contexte · Objectifs d'apprentissage ▾

Hollow Basket's Angular storefront is server-rendered for speed and SEO. The header reads the user's name and cart from localStorage and formats dates with the local clock — on the server and again in the browser. Users see a flicker, the console reports hydration errors and layout shift is high.

Mission: Find why server HTML and client rendering disagree, and make the first client render match the server while still showing personal data.

Objectifs d'apprentissage

  • Understand hydration: the client must reproduce the server's HTML first.
  • Read browser-only state after hydration.
  • Make dates and time zones deterministic.
SimulationSimulé
SSR serverCDNbrowser (hydration)
Lancer la simulation
readonly name = signal<string | null>(null);      // same initial value on server and clientreadonly cartCount = signal<number | null>(null);constructor() {  afterNextRender(() => {                          // browser only, after hydration    this.name.set(localStorage.getItem('name'));    this.cartCount.set(JSON.parse(localStorage.getItem('cart') ?? '[]').length);  });}// dates: format with an explicit time zone, or render them on the client tooreadonly offerEnds = formatDate(OFFER_END, 'mediumDate', 'en', 'UTC');

Simplification

Three symptoms with deterministic fixes. Frameworks differ in how they report mismatches (Angular NG0500, React hydration warnings). Modèle pédagogique — les chiffres illustrent un comportement, ce ne sont pas des benchmarks.

Concepts

Défis liés

Références