Skip to content

Commit

Permalink
Merge pull request #1543 from clauderic/patch-1
Browse files Browse the repository at this point in the history
fix: auto-scroll bug with multiple containers
  • Loading branch information
clauderic authored Nov 23, 2024
2 parents baad391 + bcaf7c4 commit 3c4f627
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-walls-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dnd-kit/core': patch
---

Fix a bug with auto-scroller continuing to observe stale elements, causing them to be considered as scrollable.
13 changes: 3 additions & 10 deletions packages/core/src/hooks/utilities/useRects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,10 @@ export function useRects(

const resizeObserver = useResizeObserver({callback: measureRects});

if (elements.length > 0 && rects === defaultValue) {
measureRects();
}

useIsomorphicLayoutEffect(() => {
if (elements.length) {
elements.forEach((element) => resizeObserver?.observe(element));
} else {
resizeObserver?.disconnect();
measureRects();
}
resizeObserver?.disconnect();
measureRects();
elements.forEach((element) => resizeObserver?.observe(element));
}, [elements]);

return rects;
Expand Down

0 comments on commit 3c4f627

Please sign in to comment.