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

React new Event conflict #288

Open
apuntovanini opened this issue Feb 25, 2016 · 2 comments
Open

React new Event conflict #288

apuntovanini opened this issue Feb 25, 2016 · 2 comments

Comments

@apuntovanini
Copy link

When initializing autosize inside a React component the new Event call conflicts with React internal event system. In this case the old-fashioned way of creating an event works properly

createEvent = function (name) {
  var evt = document.createEvent('Event');
  evt.initEvent(name, true, false);
  return evt;
};

I think we should add an option when initializing autosize to fallback to document.createEvent instead on new Event. What do you think?

@jackmoore
Copy link
Owner

Switching to new Event was in response to #280. Using document.createEvent will work fine in practice, but I want to stick with the new standard if possible. Can you tell me more about the conflict you are experiencing?

@apuntovanini
Copy link
Author

Sure! I initialize autosize inside a componentDidMount react function.
Autosize triggers this error:
Uncaught InvalidStateError: Failed to execute 'dispatchEvent' on 'EventTarget': The event provided is null.

on line 153

var evt = createEvent('autosize:resized');
ta.dispatchEvent(evt);

Probably the new Event(name) triggers some React stuff, but I cannot figure it out.
If I create a new Event directly inside React component I get this:

var evt = new Event('foo');
console.log(evt)
evt: Constructor {props: "foo", context: undefined, state: null}

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