Repository navigation
Replies: 2 comments
|
This is a known and well-documented pain point with Why It Happens (The Full Picture)DnD Kit uses an internal counter to generate accessible IDs like This is fundamentally an SSR incompatibility in DnD Kit's accessibility ID generation, not a Next.js bug. Fix 1 —
|
|
Thanks man |
Uh oh!
There was an error while loading. Please reload this page.
The Issue
When using @dnd-kit/core with Next.js App Router, I encountered a persistent
hydration mismatch warning on every page load:
aria-describedby="DndDescribedBy-0" ← server
aria-describedby="DndDescribedBy-1" ← client
The warning:
"A tree hydrated but some attributes of the server rendered HTML
didn't match the client properties."
Environment
Why It Happens
DnD Kit auto-generates IDs like DndDescribedBy-0, DndDescribedBy-1
incrementally. The server generates one number, the client generates
a different number — they never match.
The Fix
Only render the DndContext on the client using an isMounted pattern:
const [isMounted, setIsMounted] = useState(false);
useEffect(() => {
setIsMounted(true);
}, []);
if (!isMounted) return null;
This prevents the server from rendering DnD elements entirely —
eliminating the mismatch completely.
Questions
Although purely cosmetic — it's a bloody pain in the ass. 😂
All reactions