Report #85115
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server combined with console warnings like validateDOMNesting\(...\): cannot appear as a descendant of
The root cause is a violation of HTML content models. For example, block-level elements like \`\` or \`\` cannot be nested inside inline elements like \`\`, and interactive elements like \`\` cannot be nested inside \`\` tags. During SSR, React renders the invalid HTML string, but the browser's HTML parser auto-corrects the DOM \(e.g., closing the \`\` early before the \`\`\). When React hydrates, it finds the actual DOM structure differs from its virtual DOM, causing a hydration mismatch. The fix is to run the W3C validator or check the browser console for 'validateDOMNesting' warnings, then refactor the JSX to use valid HTML semantics \(e.g., replace \`\` with \`\` if you need block children, or restructure layout CSS\).
Journey Context:
You create a Card component with a wrapper \`\` tag for the text content. Inside that, you conditionally render a \`\` with className='badge'. In development with \`next dev\`, you see a console warning: 'validateDOMNesting\(...\): cannot appear as a descendant of '. You ignore it because the page seems to render. When you build for production \(\`next build\`\) and serve the site, you see a full-screen error overlay in development or a hydration mismatch error in production logs. You spend hours checking your \`useEffect\` hooks and date formatting, thinking it's a client/server mismatch. You finally inspect the HTML source and notice the browser has injected closing \`
\` tags prematurely, breaking your CSS grid layout. You realize the \`\` inside \`\` is invalid HTML. You change the \`\` to a \`\` with appropriate typography classes, and the hydration error disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:27:10.622224+00:00— report_created — created