-
-
Notifications
You must be signed in to change notification settings - Fork 323
feat: return whether upload started from retry/post to fix loading stuck #731
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 all commits
89d2782
929d96f
2336b88
8a89e64
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 |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ class AjaxUploader extends Component<UploadProps> { | |
|
|
||
| reqs: Record<string, any> = {}; | ||
|
|
||
| private fileInfoCache: Map<string, ParsedFileInfo> = new Map(); | ||
|
|
||
| private fileInput: HTMLInputElement; | ||
|
|
||
| private _isMounted: boolean; | ||
|
|
@@ -260,15 +262,17 @@ class AjaxUploader extends Component<UploadProps> { | |
| }; | ||
| }; | ||
|
|
||
| post({ data, origin, action, parsedFile }: ParsedFileInfo) { | ||
| post({ data, origin, action, parsedFile }: ParsedFileInfo): boolean { | ||
| if (!this._isMounted) { | ||
| return; | ||
| return false; | ||
| } | ||
|
|
||
| const { onStart, customRequest, name, headers, withCredentials, method } = this.props; | ||
|
|
||
| const { uid } = origin; | ||
|
|
||
| this.fileInfoCache.set(uid, { data, origin, action, parsedFile }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win 为 此处为每个文件保留 如果成功文件不支持重试,请在 🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你现在看看我在成功的位置删了没 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
删除操作在 You are interacting with an AI system. |
||
|
|
||
| const { onStart, customRequest, name, headers, withCredentials, method } = this.props; | ||
|
|
||
| const request = customRequest || defaultRequest; | ||
|
|
||
| const requestOption = { | ||
|
|
@@ -287,6 +291,7 @@ class AjaxUploader extends Component<UploadProps> { | |
| const { onSuccess } = this.props; | ||
| onSuccess?.(ret, parsedFile, xhr); | ||
|
|
||
| this.fileInfoCache.delete(uid); | ||
| delete this.reqs[uid]; | ||
| }, | ||
| onError: (err: UploadRequestError, ret: any) => { | ||
|
|
@@ -298,21 +303,27 @@ class AjaxUploader extends Component<UploadProps> { | |
| }; | ||
|
|
||
| onStart(origin); | ||
| this.reqs[uid] = request(requestOption, { defaultRequest }); | ||
| this.reqs[uid] = {}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '245,335p' src/AjaxUploader.tsx
rg -n 'onStart|retry\s*=|post\(' src tests/uploader.spec.tsxRepository: react-component/upload Length of output: 5349 🏁 Script executed: sed -n '1,225p' src/AjaxUploader.tsx
sed -n '319,355p' src/AjaxUploader.tsx
sed -n '330,390p' tests/uploader.spec.tsx
sed -n '1,80p' src/interface.tsx
rg -n "retry|AjaxUploader|ref=|onStart" README.md README.zh-CN.md src tests/uploader.spec.tsxRepository: react-component/upload Length of output: 21667 在
请先写入占位符,再调用 建议修复- onStart(origin);
this.reqs[uid] = {};
+ try {
+ onStart(origin);
+ } catch (e) {
+ delete this.reqs[uid];
+ throw e;
+ }🤖 Prompt for AI Agents |
||
| try { | ||
| const handle = request(requestOption, { defaultRequest }); | ||
| if (this.reqs[uid]) { | ||
| this.reqs[uid] = handle || {}; | ||
| } | ||
| } catch (e) { | ||
| delete this.reqs[uid]; | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| retry = (originFile: RcFile) => { | ||
| retry = async (originFile: RcFile): Promise<boolean> => { | ||
| const { uid } = originFile; | ||
| this.processFile(originFile, [originFile]) | ||
| .then(fileInfo => { | ||
| if (this.reqs[uid]) { | ||
| return; | ||
| } | ||
| if (fileInfo.parsedFile) { | ||
| this.post(fileInfo); | ||
| } | ||
| }) | ||
| .catch(() => {}); | ||
| const cachedFileInfo = this.fileInfoCache.get(uid); | ||
| if (!cachedFileInfo || this.reqs[uid]) { | ||
| return false; | ||
| } | ||
|
|
||
| return this.post(cachedFileInfo); | ||
| }; | ||
|
|
||
| reset() { | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
说明成功上传后的
retry返回值。 成功回调会删除fileInfoCache,所以成功上传过的文件也没有可复用缓存,调用retry会返回false。当前说明将该结果限定为文件从未上传、请求进行中或组件已卸载,并表示已上传过的文件可重试。README.md#L103-L103: 将条件改为没有可复用的缓存fileInfo,并说明成功完成后缓存已清除。README.zh-CN.md#L103-L103: 将条件改为没有可复用的缓存fileInfo,并说明成功完成后缓存已清除。📍 Affects 2 files
README.md#L103-L103(this comment)README.zh-CN.md#L103-L103🤖 Prompt for AI Agents