fix: fix clearing uploading status before upload success event #245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently the upload element clears (setting it to
false
) theuploading
status on a file element when:...but before the XHR ready state changes, and thus possibly some time before the
upload-success
orupload-failed
event is sent.This can be a problem in the Flow component when doing multi-file uploads. Basically whenever the Flow component receives a success or failure event, it will check if all files have
uploading == false
and then report that all uploads are finished. But when using multiple files that state can be true before all files have sent their success event, which can lead to the following observed event flow on the Flow component:In the example above, when File 2 notified about the success event, progress for File 3 was already at 100%, so the
uploading
flag was already set to false which lead to the Flow component reporting all finished. However the ready state of the XHR did not change yet and thus there was no success event for File 3 yet.This change modifies the behaviour of the
uploading
flag, so that it is only cleared when the XHR ready state changes, which is the same time when the element sends the success or failure event. The meaning of the uploading flag is not 100% clear to me as it is not documented, and maybe it's misused by the Flow component. However there is no other flag that indicates that the upload is finished (either success or failure) and it seems more logical to me to connect this flag to the ready state change event instead of a progress event.For tests I simply changed the expectations of the existing tests, I could not identify any further tests that would be necessary.
Fixes vaadin/vaadin-upload#368
Type of change
Checklist