fix: apply review feedback for global drag-and-drop

- Guard all drag handlers behind Files type check to avoid breaking non-file drops
- Fix counter drift on non-file drags (early return when not Files)
- Add biome-ignore for static div accessibility lint
- Improve 'all unsupported' error message clarity
- Add explanatory comment on initialFiles seeding bypass
This commit is contained in:
MaheshtheDev 2026-05-12 05:49:32 +00:00
parent 56118cacec
commit b359082566
2 changed files with 12 additions and 5 deletions

View file

@ -390,14 +390,14 @@ export default function NewPage() {
const handleGlobalDragEnter = useCallback((e: React.DragEvent) => {
e.preventDefault()
if (!e.dataTransfer.types.includes("Files")) return
globalDragCounter.current++
if (e.dataTransfer.types.includes("Files")) {
setIsGlobalDragging(true)
}
setIsGlobalDragging(true)
}, [])
const handleGlobalDragLeave = useCallback((e: React.DragEvent) => {
e.preventDefault()
if (!e.dataTransfer.types.includes("Files")) return
globalDragCounter.current--
if (globalDragCounter.current === 0) {
setIsGlobalDragging(false)
@ -405,11 +405,13 @@ export default function NewPage() {
}, [])
const handleGlobalDragOver = useCallback((e: React.DragEvent) => {
if (!e.dataTransfer.types.includes("Files")) return
e.preventDefault()
}, [])
const handleGlobalDrop = useCallback(
(e: React.DragEvent) => {
if (!e.dataTransfer.types.includes("Files")) return
e.preventDefault()
globalDragCounter.current = 0
setIsGlobalDragging(false)
@ -421,7 +423,7 @@ export default function NewPage() {
toast.error(
files.length === 1
? "This file type is not supported"
: `${files.length} files are not supported`,
: `None of the ${files.length} files are supported`,
)
}
return
@ -595,6 +597,7 @@ export default function NewPage() {
return (
<HotkeysProvider>
{/* biome-ignore lint/a11y/noStaticElementInteractions: global file drag-and-drop zone requires event handlers on a div */}
<div
className={cn(
"relative flex min-h-dvh flex-col bg-[#05080D]",

View file

@ -190,7 +190,11 @@ export function AddDocument({
}
}, [isOpen])
// Seed file queue from global drag-and-drop (only once per modal open)
// Seed file queue from global drag-and-drop (only once per modal open).
// We construct FileQueueItem objects directly instead of going through
// FileContent's addFiles (which does duplicate detection via fileQueueKey)
// because this only runs once on a freshly cleared queue, so duplicates
// are impossible.
const initialFilesConsumed = useRef(false)
useEffect(() => {
if (!isOpen) {