mirror of
https://github.com/transloadit/uppy.git
synced 2026-01-23 02:25:07 +00:00
fix xhr abort (#6097)
abortOn makes the promise (and upload) hang indefinitely, so remove it closes #5366 --------- Co-authored-by: Prakash <qxprakash@gmail.com>
This commit is contained in:
parent
9b9e698bef
commit
648f245af0
3 changed files with 30 additions and 14 deletions
6
.changeset/afraid-beers-listen.md
Normal file
6
.changeset/afraid-beers-listen.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
"@uppy/utils": patch
|
||||
"@uppy/xhr-upload": patch
|
||||
---
|
||||
|
||||
Fix `complete` event never firing for XHR and make sure the fetch aborts immediately if Uppy is cancelled before the fetch starts.
|
||||
|
|
@ -101,13 +101,6 @@ export function fetcher(
|
|||
xhr.responseType = responseType
|
||||
}
|
||||
|
||||
signal?.addEventListener('abort', () => {
|
||||
xhr.abort()
|
||||
// Using DOMException for abort errors aligns with
|
||||
// the convention established by the Fetch API.
|
||||
reject(new DOMException('Aborted', 'AbortError'))
|
||||
})
|
||||
|
||||
xhr.onload = async () => {
|
||||
try {
|
||||
await onAfterResponse(xhr, retryCount)
|
||||
|
|
@ -145,6 +138,21 @@ export function fetcher(
|
|||
})
|
||||
}
|
||||
|
||||
function abort() {
|
||||
xhr.abort()
|
||||
// Using DOMException for abort errors aligns with
|
||||
// the convention established by the Fetch API.
|
||||
reject(new DOMException('Aborted', 'AbortError'))
|
||||
}
|
||||
|
||||
signal?.addEventListener('abort', abort)
|
||||
|
||||
if (signal?.aborted) {
|
||||
// in case the signal was already aborted
|
||||
abort()
|
||||
return
|
||||
}
|
||||
|
||||
await onBeforeRequest(xhr, retryCount)
|
||||
xhr.send(body)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -235,11 +235,13 @@ export default class XHRUpload<
|
|||
if (event.lengthComputable) {
|
||||
for (const { id } of files) {
|
||||
const file = this.uppy.getFile(id)
|
||||
this.uppy.emit('upload-progress', file, {
|
||||
uploadStarted: file.progress.uploadStarted ?? 0,
|
||||
bytesUploaded: (event.loaded / event.total) * file.size!,
|
||||
bytesTotal: file.size,
|
||||
})
|
||||
if (file != null) {
|
||||
this.uppy.emit('upload-progress', file, {
|
||||
uploadStarted: file.progress.uploadStarted ?? 0,
|
||||
bytesUploaded: (event.loaded / event.total) * file.size!,
|
||||
bytesTotal: file.size,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -409,7 +411,7 @@ export default class XHRUpload<
|
|||
})
|
||||
|
||||
try {
|
||||
await uppyFetch().abortOn(controller.signal)
|
||||
await uppyFetch()
|
||||
} catch (error) {
|
||||
// TODO: create formal error with name 'AbortError' (this comes from RateLimitedQueue)
|
||||
if (error.message !== 'Cancelled') {
|
||||
|
|
@ -450,7 +452,7 @@ export default class XHRUpload<
|
|||
this.uppy.once('cancel-all', abort)
|
||||
|
||||
try {
|
||||
await uppyFetch().abortOn(controller.signal)
|
||||
await uppyFetch()
|
||||
} catch (error) {
|
||||
// TODO: create formal error with name 'AbortError' (this comes from RateLimitedQueue)
|
||||
if (error.message !== 'Cancelled') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue