diff --git a/src/renderer/src/components/sidebar/WorktreeList.tsx b/src/renderer/src/components/sidebar/WorktreeList.tsx index b1405b87d..53cf1de6f 100644 --- a/src/renderer/src/components/sidebar/WorktreeList.tsx +++ b/src/renderer/src/components/sidebar/WorktreeList.tsx @@ -1468,6 +1468,18 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp setWorktreeDragState(WORKTREE_ROW_DRAG_INITIAL_STATE) }, [cancelWorktreeNativeAutoscroll, cleanupWorktreePointerDrag]) + const setScrollRootRef = useCallback( + (node: HTMLDivElement | null) => { + if (node === null && scrollRef.current !== null) { + // Why: sidebar drag previews and autoscroll frames are tied to the + // scroll root surface; clear them before that DOM owner disappears. + clearWorktreeDrag() + } + scrollRef.current = node + }, + [clearWorktreeDrag] + ) + const flushWorktreePointerDrag = useCallback(() => { const drag = worktreePointerDragRef.current if (!drag) { @@ -2234,8 +2246,6 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp return () => document.removeEventListener('visibilitychange', handleVisibilityChange) }, [clearWorktreeDrag]) - useEffect(() => () => clearWorktreeDrag(), [clearWorktreeDrag]) - useWorkspaceStatusDocumentDrop( scrollRef, onMoveWorktreeToStatus, @@ -2251,7 +2261,7 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp return (