-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Click handler can get called twice in "non-prod" mode. #8559
Comments
changing |
Im not really aware of React internals, but from my short debug it seems that the culprit is this line - Its synchronously calling If the issue should be resolved, I would call a dibs on it. With some guidance about internals from somebody way more experience in react than I am should be quite easily fixable (I think ;) ) |
@edvinerikson changing click count does fix that but I just added that to make the issue of it being called twice more obvious. If you look at the logs the button click is called twice. Yeah it looks like an issue with the event bubbling you can see it working in my "working and not working" example by not invoking the click. Also to be clear this does not show up in a minified "prod" version of React and I would argue that "dev mode" and "prod" mode should have the same functional behavior. |
I need to look at the example closer to say what's happening, but a quick note:
This code is used for debugging purposes and isn't likely related. We're not actually dispatching a |
@aweary Just an fyi if I comment out the code that I mentioned I don't see the issue in my app which uses 14.8. |
You can see here whats the stack trace for the second Also I've verified that in this second run of Sidenote - Also when changing those lines to: open() {
this.refs.inputEl.click();
this.refs.inputEl.click();
this.refs.inputEl.click();
}, the outcome is
Which proves that each fakeNode.addEventListener(evtType, boundFunc, false); // #1
var evt = document.createEvent('Event');
// $FlowFixMe https://github.com/facebook/flow/issues/2336
evt.initEvent(evtType, false, false);
fakeNode.dispatchEvent(evt); // #2
fakeNode.removeEventListener(evtType, boundFunc, false); // #3
Question is - how to properly set up those guarded callbacks in development mode so the code benefit from it but additionally do not fall into this synchronous bug. |
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
For reference, this does not occur in the React 16 alpha: https://jsfiddle.net/6L9hgf2j/ |
@aweary I think this issue can be closed then, right? |
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
For reference - while implementation has changed the simpler fix was introduced in #10296 |
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
I think this is a bug that only happens in "non-prod" mode.
I noticed this using the react-dropzone library but I think I found a simple use case to reproduce the problem. If you check out the fiddle you can see that click handler is called twice even though the element is only clicked once. Here is an example showing it "working and not working"
I believe it has something to do with the outer div's click listener and this chunk of code:
I tested this on Chrome/Mac I have also seen this behavior on React 14.8.
The text was updated successfully, but these errors were encountered: