-
-
Notifications
You must be signed in to change notification settings - Fork 325
fix: uid conflict when multiple upload components paste at same time #686
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -95,7 +95,12 @@ class AjaxUploader extends Component<UploadProps> { | |||||
| const { multiple, directory } = this.props; | ||||||
|
|
||||||
| const items: DataTransferItem[] = [...(dataTransfer.items || [])]; | ||||||
| let files: File[] = [...(dataTransfer.files || [])]; | ||||||
| let files: File[] = [...(dataTransfer.files || [])].map((file: File) => { | ||||||
| return new File([file], file.name, { | ||||||
| type: file.type, | ||||||
| lastModified: file.lastModified, | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| if (files.length > 0 || items.some(item => item.kind === 'file')) { | ||||||
| existFileCallback?.(); | ||||||
|
|
@@ -296,7 +301,6 @@ class AjaxUploader extends Component<UploadProps> { | |||||
| delete this.reqs[uid]; | ||||||
| }, | ||||||
| }; | ||||||
|
||||||
| }; | |
| }; |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -318,7 +318,7 @@ describe('uploader', () => { | |||
| Object.defineProperty(files, 'item', { | ||||
| value: i => files[i], | ||||
| }); | ||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个测试用例很好地覆盖了并发粘贴的场景。不过,它可以更健壮一些。目前它只完成了一个上传请求,并且没有验证两个组件生成的 uid 是唯一的。
我建议更新测试以:
- 断言创建了两个独立的请求。
- 断言
uid是不同的。 - 完成两个上传请求,以确保两个组件的生命周期回调都得到测试。
await sleep(100);
expect(requests).toHaveLength(2);
expect(uid1).toBeDefined();
expect(uid2).toBeDefined();
expect(uid1).not.toEqual(uid2);
// 完成两个上传
requests[0].respond(200, {}, `["","${files[0].name}"]`);
requests[1].respond(200, {}, `["","${files[0].name}"]`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为了代码更简洁,这里的
map函数可以简化为单行表达式,使用隐式返回。