Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a circular reference possibility for empty additive dragndrop #195

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
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
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