Skip to content

Prevent BeforeInputPlugin from returning [null, null] #11848

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

Merged

Conversation

nhunzaker
Copy link
Contributor

BeforeInputEventPlugin dispatches null elements in an array if composition or beforeInput events are not extracted. This causes an extra array allocation, but more importantly creates null states in later event dispatch methods that are annoying to account for in some event system work I'm doing.

TLDR: This commit makes it so that BeforeInputPlugin never returns a null element inside an array.

The BeforeInputPlugin dispatches null elements in an array if
composition or beforeInput events are not extracted. This causes a
an extra array allocation, but more importantly creates null states in
later event dispatch methods that are annoying to account for.

This commit makes it so that BeforeInputPlugin never returns a null
element inside an array.
// Emoji test
{type: null},
{type: null},
{type: null},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, type: null are all of the null values from extractEvents, which could be a permutation of:

[null, null] // (neither a composition or beforeinput event)
[composition, beforeInput]
[null, beforeInput]
[composition, null]

So my change makes this change one of:

null
composition
beforeinput
[composition, beforeinput]

null gets filtered out by the EventPluginHub.extractEvents. It just does a basic null check, so [null, null] gets through.

Copy link
Contributor

@jquense jquense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm to me, but I can't think if this might do something weird downstream a bit. 👍

Copy link
Contributor

@aweary aweary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we tried doing this before but couldn't justify it 😄 if it simplifies some upstream code path then this LGTM

@nhunzaker
Copy link
Contributor Author

Hahaha. Looks it's me from many 🌔s ago. Dang. Thanks for sticking with me!

@nhunzaker nhunzaker merged commit cc52e06 into facebook:master Dec 14, 2017
yenshih pushed a commit to yenshih/react that referenced this pull request Jan 6, 2018
The BeforeInputPlugin dispatches null elements in an array if
composition or beforeInput events are not extracted. This causes a
an extra array allocation, but more importantly creates null states in
later event dispatch methods that are annoying to account for.

This commit makes it so that BeforeInputPlugin never returns a null
element inside an array.
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