Skip to content

Commit b4e6761

Browse files
fix(ui): remove clearData call in dropzone drop handler (#10475)
### What? This PR fixes an issue for Firefox users where dropping files over a dropzone component caused a `NoModificationAllowedError: Modifications are not allowed for this document` error due to the usage of the `dataTransfer.clearData` function. As [per MDN](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/clearData) docs, the `clearData` function does not remove files from drag operations anyway, and can only be used in the context of a `dragStart` event. ### Why? To prevent a runtime error encountered while dropping files over dropzones. ### How? By wrapping a try/catch around the `clearData` call in the `handleDrop` of the `Dropzone` component. Fixes #10472 --------- Co-authored-by: Jessica Chowdhury <jessica@trbl.design>
1 parent 5edba8e commit b4e6761

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/ui/src/elements/Dropzone/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ export function Dropzone({
7777
addFiles(e.dataTransfer.files)
7878
setDragging(false)
7979

80-
e.dataTransfer.clearData()
80+
try {
81+
e.dataTransfer.clearData()
82+
} catch {
83+
// Firefox throws NoModificationAllowedError when calling clearData() on a protected DataTransfer during drop events
84+
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/clearData#exceptions
85+
}
8186
}
8287
},
8388
[addFiles],

0 commit comments

Comments
 (0)