fix: corriger 4 erreurs console post-migration RSC
- Hydration mismatch @dnd-kit: ajouter id="notes-tabs-dnd" et id="masonry-dnd" aux DndContext pour éviter les IDs auto-incrémentaux non-déterministes (DndDescribedBy-0 server vs DndDescribedBy-3 client) - setState in render: refactorer handleDragEnd dans MasonryGrid — remplacer le double setLocalNotes() par arrayMove direct + ref pour la persistance (évite Cannot update Router while rendering MasonryGrid) - DialogTitle manquant: ajouter DialogHeader+DialogTitle sr-only dans le loading state de AutoLabelSuggestionDialog (Radix accessibility requirement) - Ajouter useRef pour tracker localNotes sans capturer de stale closure
This commit is contained in:
@@ -184,6 +184,11 @@ export function MasonryGrid({ notes, onEdit }: MasonryGridProps) {
|
||||
})
|
||||
);
|
||||
|
||||
const localNotesRef = useRef<Note[]>(localNotes)
|
||||
useEffect(() => {
|
||||
localNotesRef.current = localNotes
|
||||
}, [localNotes])
|
||||
|
||||
const handleDragStart = useCallback((event: DragStartEvent) => {
|
||||
setActiveId(event.active.id as string);
|
||||
startDrag(event.active.id as string);
|
||||
@@ -196,25 +201,25 @@ export function MasonryGrid({ notes, onEdit }: MasonryGridProps) {
|
||||
|
||||
if (!over || active.id === over.id) return;
|
||||
|
||||
setLocalNotes(prev => {
|
||||
const oldIndex = prev.findIndex(n => n.id === active.id);
|
||||
const newIndex = prev.findIndex(n => n.id === over.id);
|
||||
if (oldIndex === -1 || newIndex === -1) return prev;
|
||||
return arrayMove(prev, oldIndex, newIndex);
|
||||
});
|
||||
const reordered = arrayMove(
|
||||
localNotesRef.current,
|
||||
localNotesRef.current.findIndex(n => n.id === active.id),
|
||||
localNotesRef.current.findIndex(n => n.id === over.id),
|
||||
);
|
||||
|
||||
// Persist new order to DB (sans revalidation pour éviter le flash)
|
||||
setLocalNotes(current => {
|
||||
const ids = current.map(n => n.id);
|
||||
updateFullOrderWithoutRevalidation(ids).catch(err => {
|
||||
console.error('Failed to persist order:', err);
|
||||
});
|
||||
return current;
|
||||
if (reordered.length === 0) return;
|
||||
|
||||
setLocalNotes(reordered);
|
||||
// Persist order outside of setState to avoid "setState in render" warning
|
||||
const ids = reordered.map(n => n.id);
|
||||
updateFullOrderWithoutRevalidation(ids).catch(err => {
|
||||
console.error('Failed to persist order:', err);
|
||||
});
|
||||
}, [endDrag]);
|
||||
|
||||
return (
|
||||
<DndContext
|
||||
id="masonry-dnd"
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragStart={handleDragStart}
|
||||
|
||||
Reference in New Issue
Block a user