Skip to content

Click handler can get called twice in "non-prod" mode. #8559

@pllee

Description

@pllee

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:

if (true) {
  /**
   * To help development we can get better devtools integration by simulating a
   * real browser event.
   */
  if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
    var fakeNode = document.createElement('react');
    ReactErrorUtils.invokeGuardedCallback = function (name, func, a) {
      var boundFunc = func.bind(null, a);
      var evtType = 'react-' + name;
      fakeNode.addEventListener(evtType, boundFunc, false);
      var evt = document.createEvent('Event');
      // $FlowFixMe https://github.com/facebook/flow/issues/2336
      evt.initEvent(evtType, false, false);
      fakeNode.dispatchEvent(evt);
      fakeNode.removeEventListener(evtType, boundFunc, false);
    };
  }
}

I tested this on Chrome/Mac I have also seen this behavior on React 14.8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions