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

fix: upload drag directory can not work #562

Conversation

huiliangShen
Copy link
Contributor

@huiliangShen huiliangShen commented Jul 26, 2024

fix ant-design/ant-design#50080

function sequence() {
dirReader.readEntries((entries: InternalDataTransferItem[]) => {
const entryList = Array.prototype.slice.apply(entries);
progressFileList.push(...entryList);
// Check if all the file has been viewed
const isFinished = !entryList.length;
if (!isFinished) {
sequence();
}
});
}

出现这个bug的原因大概率是因为异步api导致,dirReader.readEntries是异步且被递归调用,walkFiles这个方法又是同步执行的,while循环结束了一会之后才会走入readEntries的回调,导致callback其实是提前拿了一个空数组就提前结束。

Copy link

vercel bot commented Jul 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
upload ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2024 10:15am

@@ -76,11 +76,11 @@ class AjaxUploader extends Component<UploadProps> {
}

if (this.props.directory) {
traverseFileTree(
const files = await traverseFileTree(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个 test 吧~~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尝试加了一个-。-

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

啥时候能发版啊。。。。。。

}
while (true) {
const results = await new Promise<InternalDataTransferItem[]>((resolve, reject) => {
dirReader.readEntries(resolve, reject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照原本的逻辑,失败了就直接无视了。这里加了 reject 后,没有做错误处理,await 后会直接挂掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zombieJ 更新了下这块的处理,看看有没有问题

break;
}

for (const entry of results) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个换一下 for (let i ...),IE 11 不支持 of loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zombieJ 已更新

@zombieJ zombieJ merged commit a0439eb into react-component:master Aug 13, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upload.Dragger directory drop does not work
3 participants