Skip to content
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

[Events] Make passiveness and priority non-configurable #19807

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Sep 10, 2020

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 for createEventHandle. Even for createEventHandle, 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 time setHandle is called — now createEventHandle also relies on the eager listeners. It also lets us remove the upgrade mechanism. It also lets us speed up the createEventHandle path 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.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 10, 2020

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:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Sep 10, 2020

Details of bundled changes.

Comparing: cd75f93...8955b5e

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.1% -0.1% 910.81 KB 909.67 KB 207.67 KB 207.47 KB NODE_DEV
ReactDOMForked-prod.js -0.5% -0.5% 380.04 KB 378.21 KB 70.76 KB 70.38 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 138.57 KB 138.57 KB 36.59 KB 36.59 KB NODE_DEV
react-dom.production.min.js -0.2% -0.2% 123.43 KB 123.22 KB 39.88 KB 39.8 KB NODE_PROD
ReactDOMForked-profiling.js -0.5% -0.5% 393.48 KB 391.65 KB 73.23 KB 72.85 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 144.73 KB 144.73 KB 36.77 KB 36.77 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.66 KB 20.66 KB 7.65 KB 7.65 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 12.83 KB 12.83 KB 5.02 KB 5.02 KB UMD_PROD
ReactDOMTesting-dev.js -0.5% -0.5% 912.66 KB 907.75 KB 205.81 KB 204.77 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 59.93 KB 59.93 KB 17.52 KB 17.52 KB NODE_DEV
ReactDOMTesting-prod.js -0.9% -0.8% 375.19 KB 371.87 KB 70.8 KB 70.21 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 12.69 KB 12.69 KB 4.94 KB 4.94 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 5.25 KB 5.25 KB 1.78 KB 1.78 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.17 KB 1.17 KB 667 B 666 B NODE_PROD
react-dom.development.js -0.1% -0.1% 957.11 KB 955.92 KB 210.33 KB 210.13 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.01 KB 1.01 KB 616 B 617 B NODE_PROD
react-dom.production.min.js -0.2% -0.2% 123.25 KB 123.04 KB 40.64 KB 40.54 KB UMD_PROD
react-dom.profiling.min.js -0.2% -0.1% 128.5 KB 128.3 KB 42.27 KB 42.22 KB UMD_PROFILING
ReactDOMForked-dev.js -0.3% -0.2% 966.27 KB 963.79 KB 215.83 KB 215.3 KB FB_WWW_DEV
react-dom.profiling.min.js -0.2% -0.2% 128.87 KB 128.66 KB 41.56 KB 41.49 KB NODE_PROFILING
ReactDOM-dev.js -0.3% -0.2% 965.6 KB 963.12 KB 216.33 KB 215.8 KB FB_WWW_DEV
ReactDOM-prod.js -0.5% -0.5% 379.61 KB 377.78 KB 70.55 KB 70.17 KB FB_WWW_PROD
ReactDOM-profiling.js -0.5% -0.5% 392.77 KB 390.94 KB 73 KB 72.62 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 20.24 KB 20.24 KB 7.5 KB 7.5 KB NODE_PROD
ReactDOMServer-prod.js 0.0% 0.0% 46.44 KB 46.44 KB 10.83 KB 10.83 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 64.85 KB 64.85 KB 18.02 KB 18.02 KB UMD_DEV

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 8955b5e

@sizebot
Copy link

sizebot commented Sep 10, 2020

Details of bundled changes.

Comparing: cd75f93...8955b5e

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.1% -0.1% 875.36 KB 874.22 KB 201.17 KB 200.97 KB NODE_DEV
ReactDOMForked-prod.js -0.4% -0.5% 391.21 KB 389.47 KB 72.52 KB 72.12 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 137.06 KB 137.06 KB 36.37 KB 36.37 KB NODE_DEV
react-dom.production.min.js -0.2% -0.2% 118.87 KB 118.66 KB 38.57 KB 38.5 KB NODE_PROD
ReactDOMForked-profiling.js -0.4% -0.5% 404.69 KB 402.96 KB 75 KB 74.61 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 143.14 KB 143.14 KB 36.57 KB 36.58 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.2 KB 20.2 KB 7.58 KB 7.58 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 12.82 KB 12.82 KB 5.01 KB 5.02 KB UMD_PROD
ReactDOMTesting-dev.js -0.5% -0.5% 940.74 KB 936.08 KB 211.35 KB 210.21 KB FB_WWW_DEV
ReactDOMTesting-prod.js -0.7% -0.7% 387.83 KB 384.93 KB 72.89 KB 72.37 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 12.68 KB 12.68 KB 4.93 KB 4.93 KB NODE_PROD
react-dom.development.js -0.1% -0.1% 919.92 KB 918.72 KB 203.71 KB 203.52 KB UMD_DEV
react-dom.production.min.js -0.2% -0.2% 118.76 KB 118.55 KB 39.28 KB 39.19 KB UMD_PROD
react-dom.profiling.min.js -0.2% -0.3% 122.65 KB 122.45 KB 40.47 KB 40.36 KB UMD_PROFILING
ReactDOMForked-dev.js -0.2% -0.3% 991.79 KB 989.37 KB 220.61 KB 220 KB FB_WWW_DEV
react-dom.profiling.min.js -0.2% -0.2% 122.94 KB 122.73 KB 39.77 KB 39.69 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.88 KB 19.88 KB 7.46 KB 7.46 KB UMD_PROD
ReactDOM-dev.js -0.2% -0.3% 991.12 KB 988.7 KB 221.05 KB 220.44 KB FB_WWW_DEV
ReactDOM-prod.js -0.4% -0.5% 390.77 KB 389.04 KB 72.27 KB 71.9 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 135.79 KB 135.79 KB 36.12 KB 36.13 KB NODE_DEV
ReactDOM-profiling.js -0.4% -0.5% 403.98 KB 402.24 KB 74.71 KB 74.34 KB FB_WWW_PROFILING
ReactDOMServer-dev.js 0.0% 0.0% 145.62 KB 145.62 KB 37.31 KB 37.31 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 64.84 KB 64.84 KB 18.01 KB 18.01 KB UMD_DEV

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against 8955b5e

let elementListenerMap = (node: any)[internalEventHandlersKey];
if (elementListenerMap === undefined) {
elementListenerMap = (node: any)[internalEventHandlersKey] = new Map();
export function getEventListenerSet(node: EventTarget): ElementListenerSet {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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.

@@ -192,35 +184,18 @@ export function createEventHandle(
// event from the list of known events has now become a breaking change for
// any code relying on the createEventHandle API.
invariant(
allNativeEvents.has(domEventName) ||
domEventName === 'beforeblur' ||
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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.

@@ -296,36 +293,24 @@ function dispatchEventsForPlugins(
processDispatchQueue(dispatchQueue, eventSystemFlags);
}

function shouldUpgradeListener(
Copy link
Collaborator Author

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.

@@ -384,21 +367,6 @@ export function listenToNativeEvent(
) {
target = (rootContainerElement: any).ownerDocument;
}
if (enablePassiveEventIntervention && isPassiveListener === undefined) {
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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.

@gaearon gaearon force-pushed the fewer-options branch 3 times, most recently from 1d5611c to b2eb0f5 Compare September 10, 2020 17:30
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 10, 2020
@gaearon gaearon force-pushed the fewer-options branch 2 times, most recently from 089247e to af8e53b Compare September 10, 2020 17:51
@gaearon gaearon merged commit 11ee82d into facebook:master Sep 14, 2020
@gaearon gaearon deleted the fewer-options branch September 14, 2020 12:54
todortotev pushed a commit to todortotev/react that referenced this pull request Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants