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

[Bug] getFiles return the old serverId on revert or undo of file in event onprocessfilerevert #1014

Open
2 tasks done
pintuiitbhi opened this issue Oct 12, 2024 · 4 comments

Comments

@pintuiitbhi
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Have you updated FilePond and its plugins?

  • I have updated FilePond and its plugins

Describe the bug

This is filepond react code. I am getting the old serverIds value of file instead of null. But when I do setTimeout of 1sec and then execute getFiles then it give me updated file (serverId as null which is expected one after revert or undo).

image

onprocessfilerevert={(file: FilePondFile) => { const serverIds = filePondRef.current?.getFiles().filter((file: FilePondFile) => file.serverId); console.log(serverIds) }}

Reproduction

`import { FilePond, registerPlugin } from 'react-filepond';

<FilePond
onprocessfilerevert={(file: FilePondFile) => {
const serverIds = filePondRef.current?.getFiles().filter((file: FilePondFile) => file.serverId);
console.log(serverIds) // this should return [null]
}}
/>`

Environment

- Device:
- OS:
- Browser:
Chrome, Firefox any version

Filepond version:
 "react-filepond": "^7.1.2",
 "filepond": "^4.31.1",
@pintuiitbhi pintuiitbhi changed the title [Bug] [Bug] getFiles return the old serverId on revert or undo of file in event onprocessfilerevert Oct 12, 2024
@rikschennink rikschennink removed the bug label Oct 14, 2024
@rikschennink
Copy link
Collaborator

I am getting the old serverIds value of file instead of null.

I'm not sure what you mean. From the code snippet it's unclear how you're setting the serverId

@pintuiitbhi
Copy link
Author

Problem is not that I am not getting the serverId but problem is getFiles doesn't give the files synchronously in case of onprocessfilerevert event. After some delay we call getFiles then it return the correct files (here I mean serverId)

` revert: async (imageId, load, error) => {
const request = new XMLHttpRequest();
request.open('DELETE', '/api/upload');
request.setRequestHeader('Content-Type', 'application/json');

      request.onload = async () => {
        if (request.status === 401) {
          error('Unauthorized: Please login.');
          router.refresh();
        } else if (request.status >= 200 && request.status < 300) {
          load();
        } else {
          error('Error in reverting file');
          router.refresh();
        }
      };

      request.onerror = () => {
        error('Error in reverting file');
      };

      request.send(
        JSON.stringify({
          imageId, // imageId is directly passed
          listingId,
        })
      );
    },`

@rikschennink
Copy link
Collaborator

Have you set forceRevert to false?

@pintuiitbhi
Copy link
Author

Have you set forceRevert to false?

no

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

No branches or pull requests

2 participants