{"success":true,"name":"root-cause-next-js-hydration-errors-never-silence-them","description":"Next.js console shows a hydration mismatch or text-content error","category":"ai-brimind","path":"ai-brimind/root-cause-next-js-hydration-errors-never-silence-them/SKILL.md","file":"SKILL.md","content":"---\nname: root-cause-next-js-hydration-errors-never-silence-them\ndescription: \"Next.js console shows a hydration mismatch or text-content error\"\n---\n\n# Root-Cause Next.js Hydration Errors, Never Silence Them\n\n## When to use\nProject is Next.js, and the browser shows 'hydration failed' or 'text content does not match', and a quick suppress trick feels tempting.\n\n## Example request\nrendering new Date() or Math.random() directly in JSX → server and browser produce different output by nature; move it to state set after mount or pass a fixed value. — Non-deterministic render. | checking window or localStorage during render → server has neither; the first render differs. Gate it behind a mounted check or a client-only component. — Browser-only API in shared render. | showing a formatted date that differs by timezone/locale → server locale is not the user's locale. — Environment-dependent formatting. | wrapping everything in suppressHydrationWarning or dynamic ssr:false to make it stop → the mismatch is still there, just hidden. — Suppression is not a fix.\n\n## Instructions\nAct like a detective who treats every Next.js hydration error as a clue, not noise. When the mismatch appears: 1) State the rule out loud: the HTML rendered on the server and the FIRST render in the browser must be identical. A hydration error means something makes them differ — your job is to name that something. 2) Read the error and locate the exact element or text it points to. Then classify the cause: (a) non-deterministic values in render (Date.now, Math.random), (b) browser-only APIs during render (window, localStorage, matchMedia), (c) environment-dependent output (timezone, locale, user-agent), (d) invalid HTML nesting (like a <div> inside a <p>) that the browser rewrites, (e) a browser extension changing the DOM. 3) Fix by making the first render deterministic: compute browser-dependent values in useEffect after mount and render a stable placeholder first, or isolate the truly client-only widget with next/dynamic ssr:false — used narrowly and with a stated reason, not as a blanket. 4) suppressHydrationWarning is reserved for the rare legit case like a timestamp that must differ — one element, with a comment saying why. 5) If you cannot yet name which of the categories caused it, keep investigating (log the server HTML vs client render) instead of guessing. Only apply a fix once the exact mismatching value is confirmed, and explain why the fix makes server and first client render identical — not just that the warning went away.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #485\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}