Skip to content

[Bug] State update in onremovefile event handler triggers file re-upload #239

Open
@IvoLeist

Description

@IvoLeist

Is there an existing issue for this?

  • I have searched the existing issues

Have you updated React FilePond, FilePond, and all plugins?

  • I have updated FilePond and its plugins

Describe the bug

Hello I am sorry for the double post, but I realized that the issue first described here: pqina/filepond#950 is probably a React specific.

Here a short summary:
I realized some odd behaviour which only happens on the live environment
https://convert-pheno.cnag.cat/, a React application built with Vite and served by nginx

The code snippet below supposed to remove a file from the uploaded files state, causes an unwanted re-triggering of the file upload.

onremovefile={(_, file) => {
   setFilesUploadFinished(false);
   const fileName = file.filename;

   // only update state if the file processing was finished (status 2 = IDLE)
   // for reference see
   // github.com/pqina/filepond-docs/blob/master/content/patterns/API/filepond-object.md#filestatus-enum
   // if below is commented out it is working on the live environment
       if (
             file.status === 2 &&
             file.getMetadata("processingAborted") !== true
       ) {
        setUploadedFiles((prev) => {
          const prevCopy = { ...prev };
          delete prevCopy[fileName];
          return prevCopy;
        });
     }
}}

Reproduction

I am not sure how to reproduce it since I guess you would need a server to show it. But if you are motivated you could fork our repo and then run the server/client with docker-compose up.

Here is a gif of the unexpected behaviour
file-deletion-reupload-loop

Environment

- Device: Any
- OS:Any
- Broser: Any
- React version: 18.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions