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

React Event System: Refactor ElementListenerMap for upgrading #18308

Merged
merged 1 commit into from
Mar 18, 2020

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Mar 13, 2020

This PR refactors the ElementListenerMap properties of the existing modern event system, React Flare responder system and the legacy event systems. They all use ElementListenerMap to register an event type against a container. Unfortunately, they don't have a way of co-ordinating when event listeners should be "upgraded" – which is the process of removing and passive/default listener and adding an active listener.

There are three states for event listeners and their passive flag. They can be true, false or void. If they are true, then the listener is passive. If they are false then the listener is active and finally, if they are void then we use the browser default and we don't specify an option value for passive when creating the listener via addEventListener. To wire all this up, we have to unify the value of ElementListenerMap, so that it's an object telling us of the last previously used passive value. We represent this as { passive: void | boolean, listener: any => void }. The upgrade order should go from passive (true) -> default (void) -> active (false).

Now we have this refactor in place, it makes it possible for the modern event system and the work going into useEvent to live together nicely and have a nice optimial system where they can share event listeners together. For Flare, we change the pattern so it uses the new format, but it really doesn't affect the others as Flare will soon be removed, so we keep the ElementListenerMap keys different (they have a _active/_passive suffixes to not clash with the legacy/modern event system listeners).

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 13, 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 1e68634:

Sandbox Source
gallant-bush-m8qvg Configuration

@sizebot
Copy link

sizebot commented Mar 13, 2020

Details of bundled changes.

Comparing: 3a0076e...1e68634

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% +0.1% 126.59 KB 126.65 KB 39.59 KB 39.61 KB NODE_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.35 KB 3.35 KB 1.27 KB 1.27 KB UMD_DEV
ReactDOM-dev.js +0.1% +0.1% 937.29 KB 938.38 KB 208.65 KB 208.8 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.19 KB 1.19 KB 698 B 700 B UMD_PROD
react-dom-server.browser.development.js 0.0% 0.0% 137.42 KB 137.42 KB 35.17 KB 35.17 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 20.62 KB 20.62 KB 7.54 KB 7.54 KB UMD_PROD
react-dom-server.browser.development.js 0.0% 0.0% 130.38 KB 130.38 KB 34.74 KB 34.74 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 20.53 KB 20.53 KB 7.5 KB 7.5 KB NODE_PROD
react-dom.development.js 0.0% -0.0% 934.26 KB 934.42 KB 204.19 KB 204.19 KB UMD_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.24 KB 58.24 KB 14.54 KB 14.54 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 122.46 KB 122.52 KB 39.15 KB 39.15 KB UMD_PROD
ReactDOMForked-dev.js +0.1% +0.1% 937.29 KB 938.38 KB 208.65 KB 208.8 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.32 KB 10.32 KB 3.5 KB 3.5 KB UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 138.16 KB 138.16 KB 35.34 KB 35.35 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% +0.1% 126.29 KB 126.35 KB 40.39 KB 40.41 KB UMD_PROFILING
ReactDOMForked-prod.js 🔺+0.3% 🔺+0.2% 383.67 KB 384.63 KB 69.81 KB 69.98 KB FB_WWW_PROD
ReactDOMServer-prod.js 0.0% 0.0% 47.01 KB 47.01 KB 10.93 KB 10.93 KB FB_WWW_PROD
react-dom.development.js 0.0% -0.0% 889.4 KB 889.54 KB 201.67 KB 201.67 KB NODE_DEV
ReactDOMForked-profiling.js +0.2% +0.2% 401.26 KB 402.22 KB 72.84 KB 73.01 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.23 KB 55.23 KB 14.31 KB 14.31 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.2% 3.69 KB 3.69 KB 1.34 KB 1.34 KB NODE_DEV
react-dom.production.min.js 0.0% 🔺+0.1% 122.61 KB 122.67 KB 38.31 KB 38.33 KB NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.05 KB 10.05 KB 3.38 KB 3.38 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.16 KB 1.16 KB 662 B 664 B NODE_PROD
ReactDOM-prod.js 🔺+0.3% 🔺+0.2% 383.67 KB 384.63 KB 69.81 KB 69.98 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.2% 401.26 KB 402.22 KB 72.84 KB 73.01 KB FB_WWW_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 2.95 KB 2.95 KB 1.18 KB 1.18 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.5% 1 KB 1 KB 609 B 612 B NODE_PROD
react-dom-test-utils.development.js 0.0% 0.0% 59.84 KB 59.84 KB 15.86 KB 15.86 KB UMD_DEV
ReactDOMTesting-dev.js 0.0% 0.0% 892.98 KB 893.32 KB 199.68 KB 199.7 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.1% 🔺+0.1% 377.43 KB 377.88 KB 69 KB 69.09 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 55.29 KB 55.29 KB 15.24 KB 15.24 KB NODE_DEV
ReactDOMTesting-profiling.js +0.1% +0.1% 377.43 KB 377.88 KB 69 KB 69.09 KB FB_WWW_PROFILING
react-dom-server.node.development.js 0.0% 0.0% 131.6 KB 131.6 KB 34.99 KB 34.99 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 12.3 KB 12.3 KB 4.53 KB 4.53 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.94 KB 20.94 KB 7.65 KB 7.65 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 🔺+0.3%

Size changes (experimental)

Generated by 🚫 dangerJS against 1e68634

@sizebot
Copy link

sizebot commented Mar 13, 2020

Details of bundled changes.

Comparing: 3a0076e...1e68634

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-profiling.js +0.2% +0.3% 427.74 KB 428.7 KB 77.65 KB 77.85 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 0.0% 12.29 KB 12.29 KB 4.52 KB 4.52 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.22 KB 58.22 KB 14.53 KB 14.53 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.5% 1013 B 1013 B 601 B 604 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.31 KB 10.31 KB 3.49 KB 3.49 KB UMD_PROD
ReactDOMForked-dev.js +0.1% +0.1% 983.17 KB 984.25 KB 218.54 KB 218.71 KB FB_WWW_DEV
ReactDOMForked-prod.js 🔺+0.2% 🔺+0.3% 410.1 KB 411.06 KB 74.54 KB 74.74 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.68 KB 3.68 KB 1.33 KB 1.33 KB NODE_DEV
react-dom.development.js 0.0% -0.0% 903.77 KB 903.94 KB 198.93 KB 198.92 KB UMD_DEV
ReactDOMForked-profiling.js +0.2% +0.3% 427.74 KB 428.7 KB 77.65 KB 77.85 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 135.83 KB 135.83 KB 34.97 KB 34.97 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.15 KB 1.15 KB 653 B 655 B NODE_PROD
react-dom.production.min.js 0.0% -0.0% 118.26 KB 118.32 KB 37.98 KB 37.98 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.16 KB 20.16 KB 7.46 KB 7.46 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 121.97 KB 122.03 KB 39.18 KB 39.2 KB UMD_PROFILING
ReactDOMTesting-dev.js 0.0% 0.0% 919.64 KB 919.97 KB 205.17 KB 205.2 KB FB_WWW_DEV
react-dom.development.js 0.0% -0.0% 860.19 KB 860.34 KB 196.43 KB 196.42 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.1% 🔺+0.1% 390.84 KB 391.29 KB 71.18 KB 71.26 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 128.87 KB 128.87 KB 34.52 KB 34.52 KB NODE_DEV
react-dom.production.min.js 0.0% 🔺+0.1% 118.34 KB 118.4 KB 37.19 KB 37.22 KB NODE_PROD
react-dom-test-utils.development.js 0.0% 0.0% 59.83 KB 59.83 KB 15.85 KB 15.85 KB UMD_DEV
ReactDOMTesting-profiling.js +0.1% +0.1% 390.84 KB 391.29 KB 71.18 KB 71.26 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 20.07 KB 20.07 KB 7.42 KB 7.42 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.34 KB 3.34 KB 1.26 KB 1.26 KB UMD_DEV
react-dom.profiling.min.js 0.0% +0.1% 122.2 KB 122.25 KB 38.39 KB 38.42 KB NODE_PROFILING
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.4% 1.17 KB 1.17 KB 689 B 692 B UMD_PROD
ReactDOM-dev.js +0.1% +0.1% 983.17 KB 984.25 KB 218.54 KB 218.71 KB FB_WWW_DEV
ReactDOMServer-dev.js 0.0% 0.0% 139.01 KB 139.01 KB 35.48 KB 35.48 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.3% 410.1 KB 411.06 KB 74.54 KB 74.74 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 55.27 KB 55.27 KB 15.23 KB 15.23 KB NODE_DEV
ReactDOMServer-prod.js 0.0% 0.0% 47.71 KB 47.71 KB 11.11 KB 11.11 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 2.94 KB 2.94 KB 1.17 KB 1.17 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.21 KB 55.21 KB 14.3 KB 14.3 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.04 KB 10.04 KB 3.37 KB 3.37 KB NODE_PROD
react-dom-server.node.development.js 0.0% 0.0% 130.09 KB 130.09 KB 34.77 KB 34.77 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.48 KB 20.48 KB 7.57 KB 7.57 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 🔺+0.1%

Size changes (stable)

Generated by 🚫 dangerJS against 1e68634

@trueadm trueadm force-pushed the change-listener-map branch 2 times, most recently from 78bdff8 to b269aa9 Compare March 16, 2020 22:38
@trueadm trueadm force-pushed the change-listener-map branch from b269aa9 to 1e68634 Compare March 17, 2020 15:33
@trueadm trueadm merged commit 7d466bc into facebook:master Mar 18, 2020
@trueadm trueadm deleted the change-listener-map branch March 18, 2020 00:15
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.

4 participants