Skip to content
This repository was archived by the owner on Jun 5, 2022. It is now read-only.

Eliminate invalid callbacks to onChange prop #51

Open
donalmurtagh opened this issue Jun 25, 2018 · 8 comments
Open

Eliminate invalid callbacks to onChange prop #51

donalmurtagh opened this issue Jun 25, 2018 · 8 comments

Comments

@donalmurtagh
Copy link
Contributor

donalmurtagh commented Jun 25, 2018

In this example usage, I upload 2 files, one of which is 2.7MB and the other is 4.2MB. Notice that the onChange prop is called back multiple times. The first time it is called back, only the first uploaded file is provided in the arguments, the second time it is called back, both files are provided in the arguments, etc.

You can see evidence of this in the console output of the example above

onChange called back with files: [File(2744170)]
onChange called back with files: (2) [File(2744170), File(4199232)]

Similarly, if 3 files are uploaded, onChange is called back 3 times with 1, 2, and 3 files respectively.

We should instead callback to onChange only once, providing all successfully processed files in the arguments.

I'm pretty sure that this bug was introduced recently, probably during the last month or two. The performance on the demo website is much better. My guess is that the demo site is using an older version of the component that does not include this bug.

@donalmurtagh donalmurtagh changed the title Improve performance by eliminating redundant callbacks Eliminate invalid callbacks to onChange Jun 26, 2018
@donalmurtagh donalmurtagh changed the title Eliminate invalid callbacks to onChange Eliminate invalid callbacks to onChange prop Jun 26, 2018
@vovkind
Copy link

vovkind commented Jun 29, 2018

Facing the same issue.

@donalmurtagh
Copy link
Contributor Author

@vovkind I've submitted a PR #54 that fixes this

@vovkind
Copy link

vovkind commented Jul 2, 2018

@donalmurtagh Do you know when fix will be released?

@donalmurtagh
Copy link
Contributor Author

donalmurtagh commented Jul 2, 2018

@vovkind I don't have permission to do releases, you'll have to ask @JakeHartnell. While you're waiting for a release, you can copy

  • index.css
  • index.js
  • UploadIcon.svg

from my PR branch into your project and use those instead of the files in node_modules/react-images-upload.

@vovkind
Copy link

vovkind commented Jul 10, 2018

Guys, I'm still facing the issue with v1.2.0

My code is the same code as in the example. Can you please check again?

@donalmurtagh
Copy link
Contributor Author

@vovkind check what? If you have a problem, please open an issue with an example that reproduces it.

@JakeHartnell JakeHartnell reopened this Jul 10, 2018
@vovkind
Copy link

vovkind commented Jul 11, 2018

@donalmurtagh

There is my code:

Definition of ImageUploader component (that's actually react-images-upload)
image

Definition of onDrop function in constructor
image

Call to _onDrop method. I added a logger to see how much this callback is being triggered
image

Here we can see that for ONE loaded image the handler method is being called twice
image

Currently, I'm using version "react-images-upload": "1.2.0"

I'm ready to provide additional information if needed. Thank you very much for your help.

@donalmurtagh
Copy link
Contributor Author

@vovkind could you create a Plunker/JSFiddle (or similar) demo that reproduces the issue with version 1.2.0?

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

No branches or pull requests

3 participants