Skip to content

Conversation

@nhunzaker
Copy link
Contributor

@nhunzaker nhunzaker commented Nov 15, 2017

This commit fixes an issue where events generated by the test utils had no type. These events are not real DOM Event objects and their constructor did not assign the provided event type property:

This through me for a bit of a loop because I didn't realize the Event class was defined locally to this module; that it wasn't a DOM event. I've renamed this constructor to FakeNativeEvent for clarity.

Additionally, it looks like the Event object was being constructed with the top level type (topClick vs click). This commit ensures that ReactTestUtils.Simulate and ReactTestUtils.SimulateNative correctly assign the event type.

Why does this matter?

Working through #11550, which evaluates assigning local listeners instead of event delegation, one of the biggest pieces of overhead is the dispatchEvent.bind(topLevelType) done for every event attachment. I believe we could just use the event type, avoiding the cost of the bind.

Other questions

Do we need a fake event constructor? Is it incorrect for ReactTestUtils.SimulateNative to dispatch a fake DOM event instead of just using the DOM Event constructor?

This commit fixes an issue where events generated by the test utils
had no type. These events are not real DOM Event objects, and their
constructor never assigned the provided event type property.

Additionally, it looks like the Event object was being constructed
with the top level type (`topClick` vs `click`). This commit ensures
that ReactTestUtils.Simulate and ReactTestUtils.SimulateNative
correctly assign the event type.
@gaearon
Copy link
Collaborator

gaearon commented Jan 5, 2018

We should just get rid of SimulateNative IMO.
#11656

@gaearon gaearon closed this Jan 5, 2018
@nhunzaker nhunzaker deleted the fix-simulate-native-event-type branch June 4, 2018 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants