@@ -1055,6 +1055,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
10551055 } | null > ( null ) ;
10561056 const dragSensorRef = useRef < SidebarPointerSensor | null > ( null ) ;
10571057 const contextDragKeyRef = useRef < string | null > ( null ) ;
1058+ const dragScrollRef = useRef < { readonly viewport : Element ; readonly top : number } | null > ( null ) ;
10581059 const [ actionSweep , setActionSweep ] = useState < {
10591060 action : SidebarSweepAction ;
10601061 keys : ReadonlySet < string > ;
@@ -1713,6 +1714,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
17131714 const finishThreadDrag = ( started : boolean ) => {
17141715 dragSensorRef . current = null ;
17151716 contextDragKeyRef . current = null ;
1717+ dragScrollRef . current = null ;
17161718 endThreadContextDrag ( ) ;
17171719 if ( started ) {
17181720 listMotionRef . current ?. release ( ) ;
@@ -1739,6 +1741,11 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
17391741 const bounds = threadListRef . current ?. getBoundingClientRect ( ) ;
17401742 return bounds !== undefined && ( point . x < bounds . left || point . x > bounds . right ) ;
17411743 } ;
1744+ // The path out of the list often crosses dnd-kit's edge zone, which autoscrolls the sidebar.
1745+ const restoreDragScroll = ( ) => {
1746+ const scroll = dragScrollRef . current ;
1747+ if ( scroll && scroll . viewport . scrollTop !== scroll . top ) scroll . viewport . scrollTop = scroll . top ;
1748+ } ;
17421749 const moveThreadContextDrag = ( point : { x : number ; y : number } ) => {
17431750 const contextDrag = pointerOutsideThreadList ( point ) ;
17441751 setDragState ( ( current ) =>
@@ -1750,6 +1757,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
17501757 endThreadContextDrag ( ) ;
17511758 return false ;
17521759 }
1760+ restoreDragScroll ( ) ;
17531761 const threads = contextDragThreads ( ) ;
17541762 const title =
17551763 threadByKeyRef . current . get ( contextDragKeyRef . current ?? "" ) ?. title . trim ( ) || "Thread" ;
@@ -1758,6 +1766,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
17581766 } ;
17591767 const dropThreadContextDrag = ( point : { x : number ; y : number } ) => {
17601768 if ( ! pointerOutsideThreadList ( point ) ) return false ;
1769+ restoreDragScroll ( ) ;
17611770 dropThreadContext ( point , contextDragThreads ( ) ) ;
17621771 return true ;
17631772 } ;
@@ -1884,6 +1893,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
18841893 if ( activeSection === undefined ) return ;
18851894 listMotionRef . current ?. suspend ( ) ;
18861895 const list = threadListRef . current ;
1896+ const viewport = list ?. closest ( '[data-slot="scroll-area-viewport"]' ) ;
1897+ dragScrollRef . current = viewport ? { viewport, top : viewport . scrollTop } : null ;
18871898 const header = list ?. querySelector < HTMLElement > ( '[data-testid="sidebar-pinned-header"]' ) ;
18881899 if ( list && header ) {
18891900 const listRect = list . getBoundingClientRect ( ) ;
0 commit comments