Skip to content

[ChangeEventPlugin] Skip extractEvents work for unhandled events#36801

Open
junhyeong9812 wants to merge 1 commit into
react:mainfrom
junhyeong9812:perf/change-event-plugin-early-bail
Open

[ChangeEventPlugin] Skip extractEvents work for unhandled events#36801
junhyeong9812 wants to merge 1 commit into
react:mainfrom
junhyeong9812:perf/change-event-plugin-early-bail

Conversation

@junhyeong9812

Copy link
Copy Markdown

Summary

ChangeEventPlugin only handles the events it registers in registerEvents:
change, click, focusin, focusout, input, keydown, keyup, and
selectionchange. However, extractEvents is invoked for every dispatched
event, and for unhandled ones it still called getNodeFromInstance and ran up
to three nodeName.toLowerCase() checks (shouldUseChangeEvent,
isTextInputElement, shouldUseClickEvent) before discarding the result. This
work happened on high-frequency events such as mousemove/pointermove.

This PR adds an early switch bail at the top of extractEvents for event
names the plugin doesn't handle, mirroring the pattern SelectEventPlugin
already uses. The guarded set is kept in sync with registerEvents. Behavior is
unchanged — it only avoids dead work on the event-dispatch hot path.

How did you test this change?

  • Existing suites pass (yarn test):
    ChangeEventPlugin, ReactDOMInput, ReactDOMSelect, ReactDOMTextarea,
    SelectEventPlugin, ReactDOMEventListener, ReactDOMEventPropagation,
    ReactBrowserEventEmitter, DOMPluginEventSystem504 tests, 11 suites.
  • yarn test --prod on the change/input/select suites → 212 tests pass.
  • Measured the avoided work: instrumenting String.prototype.toLowerCase during
    a single mousemove dispatch on a <span> showed 3 calls before this
    change and 0 after. Handled events (e.g. click) are unaffected.
  • yarn linc, yarn prettier-check, and yarn flow dom-node all pass.

ChangeEventPlugin only handles change, click, focusin, focusout, input,
keydown, keyup, and selectionchange. extractEvents nevertheless ran for
every dispatched event, calling getNodeFromInstance and up to three
nodeName.toLowerCase() checks before discarding the result for events it
does not handle — including high-frequency events like mousemove and
pointermove.

Add an early bail for unhandled event names, mirroring the switch already
used by SelectEventPlugin. The guarded set matches registerEvents.
@meta-cla

meta-cla Bot commented Jun 16, 2026

Copy link
Copy Markdown

Hi @junhyeong9812!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jun 16, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Jun 16, 2026
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.

1 participant