- Notifications
You must be signed in to change notification settings - Fork 49.8k
[Events] Make passiveness and priority non-configurable #19807
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
Conversation
| This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 8955b5e:
|
Details of bundled changes.Comparing: cd75f93...8955b5e react-dom
ReactDOM: size: 0.0%, gzip: 0.0% Size changes (experimental) |
Details of bundled changes.Comparing: cd75f93...8955b5e react-dom
ReactDOM: size: 0.0%, gzip: 0.0% Size changes (stable) |
| let elementListenerMap = (node: any)[internalEventHandlersKey]; | ||
| if (elementListenerMap === undefined) { | ||
| elementListenerMap = (node: any)[internalEventHandlersKey] = new Map(); | ||
| export function getEventListenerSet(node: EventTarget): ElementListenerSet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needs to be a Map because we won't read listeners.
| false, | ||
| 'ReactDOM.createEventHandle: setListener called on an target ' + | ||
| 'that did not have a corresponding root. This is likely a bug in React.', | ||
| if (!enableEagerRootListeners) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In eager mode, we attach to roots early, so no need to do it here anymore.
| // any code relying on the createEventHandle API. | ||
| invariant( | ||
| allNativeEvents.has(domEventName) || | ||
| domEventName === 'beforeblur' || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've needed to put them into the list so that we actually listen to them.
| listenerPriority, | ||
| ); | ||
| // Add the event to our known event types list. | ||
| addEventTypeToDispatchConfig(domEventName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do this now since we've removed support for arbitrary events for now.
| processDispatchQueue(dispatchQueue, eventSystemFlags); | ||
| } | ||
| | ||
| function shouldUpgradeListener( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this mechanism anymore.
| ) { | ||
| target = (rootContainerElement: any).ownerDocument; | ||
| } | ||
| if (enablePassiveEventIntervention && isPassiveListener === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved below since we can now decide it right before attaching the listener.
| priority === undefined | ||
| ? getEventPriorityForPluginSystem(domEventName) | ||
| : priority; | ||
| const eventPriority = getEventPriorityForPluginSystem(domEventName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React always decides the priority now.
1d5611c to b2eb0f5 Compare 089247e to af8e53b Compare af8e53b to 8955b5e Compare
These are already non-configurable in public APIs, but they are configurable in
createEventHandle. This introduces complexity for all paths, such as very hot normal event paths, but is only used forcreateEventHandle. Even forcreateEventHandle, this is not ideal because we're continually hitting these Map checks and can't benefit from eager listeners.In this PR, I'm removing support for the options argument beyond
capture. This lets us remove the Map checks every timesetHandleis called — nowcreateEventHandlealso relies on the eager listeners. It also lets us remove the upgrade mechanism. It also lets us speed up thecreateEventHandlepath because we don't need to search for Fibers or the closest containers. (I've turned invariants into warnings.)Overall, the goal is to improve perf and reduce the API surface area for something we're not yet committed to supporting. We can revisit this after the planned changes to event defaults and the event replaying refactor.