Bug when auto-scrolling with drop locations inside overflow parent
I am currently facing a bad bug in our application that can be traced back to dnd-kit. Under several circumstances, the auto scroll feature goes completely nuts. It just scrolls down as far as it can. And will get stuck there. This happens as soon as the DragOverlay enters a droppable. For a better understanding see the following GIF:
I tried to figure out what is going on there. And this is what I was able to come up with: The issue happens, when the droppable has a parent somewhere up the tree that has any kind of overflow set. There is logic in dnd kit that is searching for scrollable ancestors. And for some reason I dont unserstand, as soon as the the DragOverlay is over a drop location, it uses this droppable as a search reference for scrollable ancestors. So it will detect the aditional parent with the set overflow. Then, further into the logic, scrollableAncestorRects are calculated from the detected scrollableAncestors. And I THINK this is where the source of the issue could be. Because when exiting the drop location again, the scroll ancestors are searched again and the additional parent with the overflow is removed from scrollableAncestors. But this is not the case for the Rects. The reducer function for calculating the scrollableAncestorRects is defined INSIDE the hook function. I think thats pretty bad. Because this closure function still has the context of the very first hook function call. And the elements it sees are still the same from back then. Maybe I am wrong there. But what I could see was, that other than the scrollableAncestors, the scrollableAncestorRects are not updated properly after leaving the drop location.
Unfortunately this is where my knowledge hits its limit. But still I hope my research can help fixing this issue.
Here is the code sandbox: https://codesandbox.io/p/sandbox/dnd-kit-issue-jnch7n
I think the scrollableAncestors search is generally a bit trouble prone. It's highly situational. In my opinion maybe a really good, easy and quick solution could be to allow passing scrollableAncestors from outside as an override and let people define by themselves. Hope my input helps.
I got the same issue there