Skip to main content
InterviewHubPRO
Section Overview
Q18

Question 18 of 50

Part 2: Core Architecture & Data Fetching (Mid-Level)

36%
Nuxt & Universal SSR (50 Qs)•Part 2: Core Architecture & Data Fetching (Mid-Level)

What causes Client Hydration Mismatches in Nuxt 3 and how do you fix them?

senior LevelCLISSR & HydrationSystem Design

In Simple Words: A hydration mismatch occurs when the HTML generated by the Node.js server does not match the Virtual DOM tree produced during the initial client-side render pass. When Vue detects the divergence, it discards or forcefully repaints the DOM, causing flashing and performance degradation.

Common Causes & Fixes:

  1. Invalid HTML Nesting: Putting a <div> inside a <p> tag causes browser HTML parsers to auto-close the <p>, breaking Vue's node hierarchy.
  2. Accessing Browser-Only State During Render: Rendering Date.now(), Math.random(), or window.innerWidth directly in templates.
  3. Fix: Use <ClientOnly> for client-only widgets, compute non-deterministic dates on the server and pass via useState, or initialize browser values inside onMounted().