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-interactions] Upgrade passive event listeners to active listeners #17513

Merged
merged 2 commits into from
Dec 4, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Dec 3, 2019

One of the long standing things we've wanted to do when working on React Flare, was to be able to upgrade passive event listeners to active event listeners where possible. This removes the need to have two separate event listeners attached to the document at the same time.

If we first attach an active listener of a given type, and then later try to add a passive listener of the same type, we don't both – instead we handle the logic for both active and passive events inside the same active event listener. Furthermore, if we first attach a passive event for a given type, and then later try to add an active listener of the same type, we first remove the passive listener from the DOM and then we add the active listener to the DOM.

The logic in the responder system might seem a little convoluted because of how responders target/root events are designed. Thankfully, this won't be the case with the Listener API and we use a much simpler control flow when dealing with events with that API.

I also remove the responder logic for passiveSupported as it no longer felt relevant given this change, plus it was never used in any event responders. To enable the changes, we change the Listener Set to a Listener Map, so we can store the event listener callback we used when setting up the DOM event listener (this enables us to remove it again later).

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 3, 2019

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 689ed6d:

Sandbox Source
quizzical-haze-n0suv Configuration

@sizebot
Copy link

sizebot commented Dec 3, 2019

Details of bundled changes.

Comparing: 54f6673...689ed6d

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% 0.0% 123.53 KB 123.55 KB 38.84 KB 38.84 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 140.46 KB 140.46 KB 36.91 KB 36.91 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 20.39 KB 20.39 KB 7.48 KB 7.48 KB UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.18 KB 11.18 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 711 B 710 B UMD_PROD
ReactDOMServer-dev.js 0.0% -0.0% 139.73 KB 139.73 KB 35.46 KB 35.46 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% -0.0% 54.48 KB 54.48 KB 15.22 KB 15.22 KB NODE_DEV
ReactDOMServer-prod.js 0.0% -0.0% 48.91 KB 48.91 KB 11.18 KB 11.18 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.95 KB 10.95 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.05 KB 1.05 KB 642 B 641 B NODE_PROD
react-dom.development.js +0.1% +0.1% 954.05 KB 954.86 KB 215.67 KB 215.82 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 119.59 KB 119.6 KB 38.42 KB 38.42 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 123.27 KB 123.28 KB 39.53 KB 39.54 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 948.12 KB 948.93 KB 214.09 KB 214.24 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 119.73 KB 119.74 KB 37.79 KB 37.79 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.14 KB 60.14 KB 15.8 KB 15.8 KB UMD_DEV
ReactDOM-dev.js +0.1% +0.1% 976.15 KB 977.2 KB 216.61 KB 216.82 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.3% 402.83 KB 403.79 KB 73.37 KB 73.58 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 59.82 KB 59.82 KB 15.67 KB 15.66 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
ReactDOM-profiling.js +0.2% +0.3% 403.79 KB 404.75 KB 73.89 KB 74.09 KB FB_WWW_PROFILING
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 698 B 697 B NODE_PROD

ReactDOM: size: 0.0%, gzip: -0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 689ed6d

@sizebot
Copy link

sizebot commented Dec 3, 2019

Details of bundled changes.

Comparing: 54f6673...689ed6d

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.development.js 0.0% -0.0% 136.37 KB 136.37 KB 35.91 KB 35.91 KB NODE_DEV
react-dom.development.js +0.1% +0.1% 954.03 KB 954.84 KB 215.65 KB 215.8 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.85 KB 19.85 KB 7.38 KB 7.38 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom.production.min.js 0.0% 🔺+0.1% 116.18 KB 116.19 KB 37.45 KB 37.48 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 703 B 702 B UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.75 KB 119.76 KB 38.56 KB 38.57 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 948.1 KB 948.91 KB 214.07 KB 214.22 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.7 KB 3.7 KB 1.5 KB 1.49 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116.29 KB 116.3 KB 36.86 KB 36.86 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.13 KB 60.13 KB 15.79 KB 15.79 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.04 KB 1.04 KB 635 B 633 B NODE_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.98 KB 120 KB 37.87 KB 37.87 KB NODE_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 59.8 KB 59.8 KB 15.66 KB 15.66 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.17 KB 11.17 KB 4.14 KB 4.14 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 54.47 KB 54.47 KB 15.21 KB 15.21 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom-server.browser.development.js 0.0% -0.0% 140.44 KB 140.44 KB 36.91 KB 36.91 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 690 B 689 B NODE_PROD

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

Size changes (stable)

Generated by 🚫 dangerJS against 689ed6d

@trueadm trueadm force-pushed the flare-passive-active-listners branch from f510cc6 to d22e0af Compare December 4, 2019 12:12
@trueadm trueadm merged commit acfe4b2 into facebook:master Dec 4, 2019
@trueadm trueadm deleted the flare-passive-active-listners branch December 4, 2019 19:30
trueadm added a commit to trueadm/react that referenced this pull request Dec 4, 2019
sebmarkbage added a commit to sebmarkbage/react that referenced this pull request Jan 30, 2020
sebmarkbage added a commit to sebmarkbage/react that referenced this pull request Jan 30, 2020
sebmarkbage added a commit that referenced this pull request Jan 30, 2020
* Add test of Event Replaying using Flare

* Fix Event Replaying in Flare by Eagerly Adding Active Listeners

This effectively reverts part of #17513
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.

4 participants