fix(kanban): infinite ref-merge loop + drag lag
Two issues: 1. "Maximum update depth exceeded" inside Mantine's useMergedRef during drag. Root cause: the `data` object passed to dnd-kit's `useSortable` in KanbanCard and KanbanColumn was re-created on every render. Mantine Paper composes its internal ref with the consumer ref via useMergedRef, which uses a useCallback whose deps array contains the refs themselves. Whenever the underlying setNodeRef from useSortable became unstable (because dnd-kit's internal state churned on data identity change), the merged ref was reassigned each commit -> setState inside the ref callback -> next render -> new data identity -> loop. Wrap the sortable data in useMemo keyed on its real inputs. 2. Drag feels laggy. Each card listens to a 1-second `now` clock that re-renders the entire board to refresh the "time in column" label. Pause that interval while a drag is active so dnd-kit's per-pixel reconciliation does not also re-mount/re-layout every card every second. Tick resumes the moment the drag ends. Also move the Select `data` array for the column max-time popover from an inline expression to a module-level constant; same array identity across all column instances and renders -> Mantine Combobox stops re-running its diffing effect for free. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -300,10 +300,14 @@ export function App() {
|
||||
reloadRequesters();
|
||||
}, [reloadTags, reloadRequesters]);
|
||||
|
||||
// Tick de reloj para "tiempo en columna" en cards. Pausamos durante drag
|
||||
// porque dispara re-render de TODAS las cards cada segundo y el drag de
|
||||
// dnd-kit sufre tirones serios con muchos elementos.
|
||||
useEffect(() => {
|
||||
if (activeCard || activeColumnId) return;
|
||||
const t = setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
}, [activeCard, activeColumnId]);
|
||||
|
||||
useEffect(() => {
|
||||
const t = setInterval(() => {
|
||||
|
||||
Reference in New Issue
Block a user