Skip to content

Commit

Permalink
Fixes a circular reference possibility for empty additive dragndrop (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tewr authored Jul 20, 2023
1 parent 592438d commit b159a32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/Blazor.FileReader/script/DragnDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,16 @@ function RegisterDropEvents(this: FileReaderComponent, element: HTMLElement, reg
ev.preventDefault();

if (ev.target instanceof HTMLElement) {
const existingFilePromise = this.elementDataTransfers.get(element);
const filePromise = new Promise<FileList>(async (resolve, reject) => {
try {
let files = await getFilesAsync(ev.dataTransfer);
if (registerOptions.additive) {
const existing = await this.elementDataTransfers.get(element) ?? new FileList();
if (existing.length > 0) {
files = new ConcatFileList(existing, files);
if (existingFilePromise) {
const existing = await existingFilePromise ?? new FileList();
if (existing.length > 0) {
files = new ConcatFileList(existing, files);
}
}
}
resolve(files);
Expand Down
9 changes: 6 additions & 3 deletions src/Blazor.FileReader/wwwroot/FileReaderComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@
const dropHandler = (ev) => {
ev.preventDefault();
if (ev.target instanceof HTMLElement) {
const existingFilePromise = this.elementDataTransfers.get(element);
const filePromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
var _a;
try {
let files = yield getFilesAsync(ev.dataTransfer);
if (registerOptions.additive) {
const existing = (_a = yield this.elementDataTransfers.get(element)) !== null && _a !== void 0 ? _a : new FileList();
if (existing.length > 0) {
files = new ConcatFileList_1.ConcatFileList(existing, files);
if (existingFilePromise) {
const existing = (_a = yield existingFilePromise) !== null && _a !== void 0 ? _a : new FileList();
if (existing.length > 0) {
files = new ConcatFileList_1.ConcatFileList(existing, files);
}
}
}
resolve(files);
Expand Down
Loading

0 comments on commit b159a32

Please sign in to comment.