Skip to content

Commit aacd8bf

Browse files
committed
fix: prevent dnd hydration errors
1 parent 17fb3dc commit aacd8bf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/ChessboardProvider.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
use,
1717
useCallback,
1818
useEffect,
19+
useId,
1920
useMemo,
2021
useRef,
2122
useState,
@@ -300,6 +301,9 @@ export function ChessboardProvider({
300301
// the animation timeout whilst waiting for animation to complete
301302
const animationTimeoutRef = useRef<NodeJS.Timeout | null>(null);
302303

304+
// unique id for dnd context, we need this to prevent hydration issues
305+
const dndId = useId();
306+
303307
// if the position changes, we need to recreate the pieces array
304308
useEffect(() => {
305309
const newPosition =
@@ -667,6 +671,7 @@ export function ChessboardProvider({
667671
onDragEnd={handleDragEnd}
668672
onDragCancel={handleDragCancel}
669673
sensors={sensors}
674+
id={dndId}
670675
>
671676
{children}
672677
</DndContext>

0 commit comments

Comments
 (0)