Question presented to candidate: "After we moved our Nuxt app to SSR, the console shows 'Hydration completed but contains mismatches' on some pages, and a dark-mode class sometimes appears wrong. How do you find out what is mismatching, and how do you fix it properly rather than just hiding the warning?"
What a strong answer should cover:
- What a mismatch is: the first client render does not produce the HTML the server sent, so hydration cannot simply adopt the DOM.
- Reading the dev warning: the type (text, children, class, style, attribute, node), the server value vs the client value, and the component trace.
- Typical causes:
Date/Math.random(),window/localStoragein setup, locale or time-zone formatting, missing state transfer, and invalid HTML nesting that the browser parser rewrites. - What Vue does about it: text and node mismatches are patched, while class, style and attribute mismatches are check-only and stay wrong in production.
- The fixes: move browser-only work to
onMounted,useId()for IDs, transfer state (useState/useFetchin Nuxt),<ClientOnly>, anddata-allow-mismatchonly for genuinely expected differences. - Production diagnostics:
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__, ordebug: { hydration: true }in Nuxt.
Clarifying questions expected:
- "Does it happen in development too, or only in production builds?"
- "Is the differing value user-specific (theme, locale, time zone) or random?"
Code / implementation expected: Optional โ a component that renders a neutral value on the server and fills in a browser-only value in onMounted.