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 state issues with xhr upload #5676

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qxprakash
Copy link

this attempts to fix #5669 , I have explained the complete walkthrough and intution of the solution in #5669 comments

Copy link
Contributor

github-actions bot commented Mar 5, 2025

Diff output files
diff --git a/packages/@uppy/core/lib/Uppy.js b/packages/@uppy/core/lib/Uppy.js
index 1ba8ade..43c50c8 100644
--- a/packages/@uppy/core/lib/Uppy.js
+++ b/packages/@uppy/core/lib/Uppy.js
@@ -1023,7 +1023,19 @@ export class Uppy {
       const waitingFileIDs = [];
       Object.keys(files).forEach(fileID => {
         const file = this.getFile(fileID);
-        if (!file.progress.uploadStarted && currentlyUploadingFiles.indexOf(fileID) === -1) {
+        if ((!file.progress.uploadStarted || file.error) && currentlyUploadingFiles.indexOf(fileID) === -1) {
+          if (file.error) {
+            this.setFileState(file.id, {
+              error: file.error,
+              progress: {
+                ...file.progress,
+                uploadStarted: null,
+                bytesUploaded: false,
+                percentage: 0,
+                uploadComplete: false,
+              },
+            });
+          }
           waitingFileIDs.push(file.id);
         }
       });
@@ -1300,6 +1312,7 @@ function _addListeners2() {
       }));
       newError.isUserFacing = true;
       newError.details = error.message;
+      newError.file = file;
       if (error.details) {
         newError.details += ` ${error.details}`;
       }
diff --git a/packages/@uppy/xhr-upload/lib/index.js b/packages/@uppy/xhr-upload/lib/index.js
index 8011f6f..8da03c9 100644
--- a/packages/@uppy/xhr-upload/lib/index.js
+++ b/packages/@uppy/xhr-upload/lib/index.js
@@ -211,7 +211,7 @@ export default class XHRUpload extends BasePlugin {
           for (const file of files) {
             this.uppy.emit("upload-error", this.uppy.getFile(file.id), buildResponseError(request, error), request);
           }
-          throw error;
+          return undefined;
         }
       };
     };

@qxprakash qxprakash changed the title fix xhr upload not resolving with failed file state and infinte loading state on hitting upload twice fix state issues with xhr upload Mar 5, 2025
@qxprakash
Copy link
Author

qxprakash commented Mar 5, 2025

@Murderlon learned a lot trying to fix this issue , is there any debugger configuration ? , to run my local build in debug mode while it executes , because for now I am using manual log statements to figure out the flow and which is not very efficient at times , would love be happy to explore a more efficient way to do it.

@Murderlon
Copy link
Member

Murderlon commented Mar 5, 2025

Thanks for looking into this!

Unfortunately it seems this is just suppressing the issue instead of solving it. Now nothing happens but we do fire completed events as if something did happen.

I think the solution is either

  1. making upload() idempotent and can automatically behave similar to retryAll()
  2. detecting this is a subsequent call to upload() and we throw an error or ignore and print to the console. This would be best paired with a more DX-friendly way of knowing which state Uppy is in so the implementer can easily switch between upload() and retryAll().

Uppy's codebase has become quite messy over the years so I didn't expect you to find this out immediately. I'll take a quick look to see what makes the most sense as a next step.

Screenshot 2025-03-05 at 10 53 40

@qxprakash
Copy link
Author

qxprakash commented Mar 5, 2025

Thanks for looking into this!

Unfortunately it seems this is just suppressing the issue instead of solving it. Now nothing happens but we do fire completed events as if something did happen.

I think the solution is either

  1. making upload() idempotent and can automatically behave similar to retryAll()
  2. detecting this is a subsequent call to upload() and we throw an error or ignore and print to the console. This would be best paired with a more DX-friendly way of knowing which state Uppy is in so the implementer can easily switch between upload() and retryAll().

Uppy's codebase has become quite messy over the years so I didn't expect you to find this out immediately. I'll take a quick look to see what makes the most sense as a next step.

Screenshot 2025-03-05 at 10 53 40

Yeah Completely agree , I myself was not satisfied hence with the solution, hence I made it a draft PR, since it was with a bunch of workarounds all along , will keenly watch out for the solution as you fix it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uppy.upload() does not work with XHRUploader
2 participants