Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
if (!isDragging) {
isDraggingRef.current = true
setIsDragging(true)
} else if (scrollAnimationRef.current === null) {
scrollAnimationRef.current = requestAnimationFrame(handleAutoScroll)
}

return true
},
[isDragging]
[isDragging, handleAutoScroll]
)

const getSiblingItems = useCallback(
Expand Down Expand Up @@ -616,6 +618,31 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
siblingsCacheRef.current.clear()
}, [])

useEffect(() => {
if (!isDragging) return
const container = scrollContainerRef.current
if (!container) return
const onLeave = (e: DragEvent) => {
const related = e.relatedTarget as Node | null
if (related && container.contains(related)) return
if (scrollAnimationRef.current !== null) {
cancelAnimationFrame(scrollAnimationRef.current)
scrollAnimationRef.current = null
}
dropIndicatorRef.current = null
setDropIndicator(null)
setHoverFolderId(null)
}
container.addEventListener('dragleave', onLeave)
window.addEventListener('drop', handleDragEnd, true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture-phase window drop listener preempts React onDrop handler

High Severity

The window.addEventListener('drop', handleDragEnd, true) registers a capture-phase listener. When dropping inside the sidebar, this fires before React's onDrop handler (handleDrop). Since handleDragEnd sets dropIndicatorRef.current = null, the subsequent handleDrop reads a null indicator and returns early without processing the reorder. This breaks internal sidebar drag-and-drop reordering entirely.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6d5cad0. Configure here.

window.addEventListener('dragend', handleDragEnd, true)
return () => {
container.removeEventListener('dragleave', onLeave)
window.removeEventListener('drop', handleDragEnd, true)
window.removeEventListener('dragend', handleDragEnd, true)
}
}, [isDragging, handleDragEnd])

const setScrollContainer = useCallback((element: HTMLDivElement | null) => {
scrollContainerRef.current = element
}, [])
Expand Down
Loading