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?

Senior Engineer8 minDebugging labCode challenge
angularssrnextjslocalstorage
Mission:Find why server HTML and client rendering disagree, and make the first client render match the server while still showing personal data.Context · Learning objectives ▾

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.

Learning objectives

  • Understand hydration: the client must reproduce the server's HTML first.
  • Read browser-only state after hydration.
  • Make dates and time zones deterministic.
SimulationSimulated
SSR serverCDNbrowser (hydration)
Run 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). Educational model — numbers illustrate behaviour, they are not benchmarks.

Concepts

Related challenges

References