Skip to content

Commit

Permalink
fix: handle getFile returning null and close react-dropzone#106, close
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandjitsu authored and jonkoops committed Nov 27, 2024
1 parent e5a197f commit b4c9613
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/file-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ async function fromDataTransferItem(
typeof (item as any).getAsFileSystemHandle === "function"
) {
const h = await (item as any).getAsFileSystemHandle();
const file = await h.getFile();
file.handle = h;
return toFileWithPath(file);
if (h === null) {
throw new Error(`${item} is not a File`);
}
// It seems that the handle can be `undefined` (see https://github.com/react-dropzone/file-selector/issues/120),
// so we check if it isn't; if it is, the code path continues to the next API (`getAsFile`).
if (h !== undefined) {
const file = await h.getFile();
file.handle = h;
return toFileWithPath(file);
}
}
const file = item.getAsFile();
if (!file) {
Expand Down

0 comments on commit b4c9613

Please sign in to comment.