eslint-plugin-validate-jsx-nesting
ESLint plugin to validate JSX nesting at compile time
The Problem
Certain HTML elements have nesting restrictions. For example, placing a <p> inside another <p> is invalid. When browsers encounter this, they silently modify the DOM to fix it.
If you write this JSX:
The browser creates this DOM:
The outer paragraph gets closed early, and the inner paragraph ends up as a sibling. This mismatch between your JSX and the actual DOM causes hydration errors in React and other frameworks.
The Solution
This ESLint plugin catches invalid nesting in your editor as you type. No waiting for build errors or production bugs:
Setup
Install eslint-plugin-validate-jsx-nesting and add it to your ESLint config: