[ChangeEventPlugin] Skip extractEvents work for unhandled events#36801
[ChangeEventPlugin] Skip extractEvents work for unhandled events#36801junhyeong9812 wants to merge 1 commit into
Conversation
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.
|
Hi @junhyeong9812! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
ChangeEventPluginonly handles the events it registers inregisterEvents:change,click,focusin,focusout,input,keydown,keyup, andselectionchange. However,extractEventsis invoked for every dispatchedevent, and for unhandled ones it still called
getNodeFromInstanceand ran upto three
nodeName.toLowerCase()checks (shouldUseChangeEvent,isTextInputElement,shouldUseClickEvent) before discarding the result. Thiswork happened on high-frequency events such as
mousemove/pointermove.This PR adds an early
switchbail at the top ofextractEventsfor eventnames the plugin doesn't handle, mirroring the pattern
SelectEventPluginalready uses. The guarded set is kept in sync with
registerEvents. Behavior isunchanged — it only avoids dead work on the event-dispatch hot path.
How did you test this change?
yarn test):ChangeEventPlugin,ReactDOMInput,ReactDOMSelect,ReactDOMTextarea,SelectEventPlugin,ReactDOMEventListener,ReactDOMEventPropagation,ReactBrowserEventEmitter,DOMPluginEventSystem→ 504 tests, 11 suites.yarn test --prodon the change/input/select suites → 212 tests pass.String.prototype.toLowerCaseduringa single
mousemovedispatch on a<span>showed 3 calls before thischange and 0 after. Handled events (e.g.
click) are unaffected.yarn linc,yarn prettier-check, andyarn flow dom-nodeall pass.