-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix/multiple file upload race condition sorting #15923
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: 3.x
Are you sure you want to change the base?
Fix/multiple file upload race condition sorting #15923
Conversation
When multiple files are uploaded in parallel, the order was determined by the upload completion time rather than the order selected by the user. This change retrieves the current file order from FilePond after all files finish processing and sends that order to the backend via reorderUploadedFilesUsing, ensuring the visible sort order is maintained. Resolves the multiple file upload race condition.
Extracted the duplicate code into updateFileOrder so both 'reorderfiles' and 'handleFileProcessing' use the same logic.
@angus-mcritchie what do you think of this, does it fix the problem for you? |
That fixes it @danharrin! Great work @husseincak 👏 |
I notice an issue. It only works when you put If not, the files will not be reordered because in the BaseFileUpload.php -
Now, im not sure if i have to touch this or delete that if, because it can have another consecuences. |
You can probably remove that block |
@@ -317,6 +306,9 @@ export default function fileUploadFormComponent({ | |||
return | |||
} | |||
|
|||
// Get the current order as displayed in FilePond and pass it to the backend. | |||
await this.updateFileOrder() |
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.
Can we skip this if there is only 1 file? Otherwise there is another network request for no reason.
Are there any other situations where it can be skipped?
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.
In principle, I see three easy cases to check:
- No files: If there are no files, there's nothing to reorder.
- Only one file: With just one file, no ordering is needed.
- Order unchanged: If the new order is identical to the previous order (i.e., nothing has actually moved, like appending files at the end and is already correct), we can skip the request.
There's also a slightly more complex case that I'm not sure is worth pursuing—I haven't explored it thoroughly yet:
- Debouncing rapid events: If multiple reorder events fire in quick succession, a debounce check might avoid redundant requests (though this may be overkill depending on how often it occurs).
I'll review this further, and I think I can handle the first three options. This is my first PR, so feel free to let me know if I have to follow any etiquette or convention or Im doing something wrong.
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.
Just fixing those cases would be great, or we will get complaints that it is inefficient :)
Hi, are you able to making the suggested changes so we can merge the PR? |
Hi, I managed to make the optimization changes (I have them another branch locally). The problem is that I realized the bug isn't completely fixed. In most cases, the file order is correct after uploads or edits, but there are still some situations where it fails. I have been trying to solve it with no luck. It looks like FilePond’s internal ordering logic is still interfering in some edge cases, even with the current workaround. Where the bug happens: this.pond.files = await this.getFiles() The array returned by Example scenario:
If you insert a two new files (
But after the saving, the order becomes:
If you refresh the browser, the order is showed correctly, so it means that in the server are being save correctly:
Summary:
Here is a video of what is happening exactly: Screen.Recording.on.2025-05-23.at.01-11-53.mp4 |
Description
As described in #15308, when multiple files are uploaded in parallel, the order was determined by the upload completion time rather than the order selected by the user. This change retrieves the current file order from FilePond after all files finish processing and sends that order to the backend via reorderUploadedFilesUsing, ensuring the visible sort order is maintained.
Resolves the multiple file upload race condition.
Visual changes
Before (video): https://github.com/user-attachments/assets/c0c25759-42f2-4d52-a812-37a8a7688c0c
After (video): https://github.com/user-attachments/assets/993fd041-3812-4c9f-b7b7-86042931f527
Functional changes
composer cs
command.