From dfa57ad57c970947b361db0bacf4d93fce5f421e Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 11:32:50 -0700 Subject: [PATCH] fix: clear worktree drag from sidebar root cleanup (#3480) --- .../src/components/sidebar/WorktreeList.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 (