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

Experimental Event API: Redesign event responder propagation #15408

Merged
merged 4 commits into from
Apr 13, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 13, 2019

This PR aims at tackling a class of issues, confusion and bugs with how event responder propagate in the different phases and how stopPropagation works. The previous implementation didn't correctly ensure event components in the capture phase were fired in the right order. This PR revamps the entire process, cleaning up code along the way and improving performance significantly compared to before.

This also fixes a bunch of bugs along the way, which now have tests added to ensure we don't regress. Another big change is that it is expected the the event responder onEvent returns a boolean indicating if the event module itself should prevent propagation after. Rather than before, where you'd use dispatchStopPropagation, which didn't make a lot of sense. Furthermore, the responder event object passed to the callbacks (like onEvent) now has a phase integer property. The phase property indicates what the current phase is:

  • 0: root phase
  • 1: bubble phase
  • 2: capture phase

The ordering of these phases, when events come in:

Capture target event types -> Bubble target event types -> Root event types

This can be used to properly dispatch events in their relative phases, rather than passing capture on the config object of dispatchEvent. So, if you want to dispatch an event in the capture phase, you need to check the current phase that the event onEvent is in and ensure you're in the same phase as what you want to dispatch in.

I also removed the new responder event system from using the plugin event system's bookkeeping logic – it was never actually needed and just added overhead on each event pass. So now the fork for the different event systems happens in dispatchEvent.

@sizebot
Copy link

sizebot commented Apr 13, 2019

ReactDOM: size: -0.1%, gzip: -0.1%

Details of bundled changes.

Comparing: a30e7d9...157f4cb

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.2% +0.1% 809.01 KB 810.69 KB 184.87 KB 185.02 KB UMD_DEV
react-dom.production.min.js -0.1% -0.1% 103.68 KB 103.58 KB 33.69 KB 33.65 KB UMD_PROD
react-dom.profiling.min.js -0.1% -0.1% 106.83 KB 106.73 KB 34.64 KB 34.61 KB UMD_PROFILING
react-dom.development.js +0.2% +0.1% 803.5 KB 805.17 KB 183.33 KB 183.49 KB NODE_DEV
react-dom.production.min.js -0.1% -0.1% 103.67 KB 103.57 KB 33.14 KB 33.1 KB NODE_PROD
react-dom.profiling.min.js -0.1% -0.1% 107 KB 106.9 KB 34 KB 33.95 KB NODE_PROFILING
ReactDOM-dev.js +0.2% +0.1% 827.66 KB 829.52 KB 184.61 KB 184.87 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.4% 🔺+0.2% 336 KB 337.35 KB 62.53 KB 62.68 KB FB_WWW_PROD
ReactDOM-profiling.js +0.4% +0.2% 341.38 KB 342.74 KB 63.46 KB 63.61 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.2% +0.1% 809.34 KB 811.02 KB 185.01 KB 185.16 KB UMD_DEV
react-dom-unstable-fire.production.min.js -0.1% -0.1% 103.7 KB 103.6 KB 33.7 KB 33.66 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js -0.1% -0.1% 106.85 KB 106.75 KB 34.65 KB 34.61 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.2% +0.1% 803.82 KB 805.5 KB 183.47 KB 183.62 KB NODE_DEV
react-dom-unstable-fire.production.min.js -0.1% -0.1% 103.69 KB 103.59 KB 33.15 KB 33.11 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js -0.1% -0.1% 107.01 KB 106.91 KB 34 KB 33.96 KB NODE_PROFILING
ReactFire-dev.js +0.2% +0.1% 826.85 KB 828.71 KB 184.62 KB 184.89 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.4% 🔺+0.3% 323.97 KB 325.33 KB 60.08 KB 60.23 KB FB_WWW_PROD
ReactFire-profiling.js +0.4% +0.3% 329.32 KB 330.68 KB 61.04 KB 61.19 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% -0.0% 10.52 KB 10.52 KB 3.9 KB 3.89 KB UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 53.91 KB 53.91 KB 14.91 KB 14.91 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.31 KB 10.31 KB 3.82 KB 3.82 KB NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.69 KB 10.69 KB 3.67 KB 3.67 KB UMD_PROD
react-dom-server.browser.development.js 0.0% -0.0% 136.73 KB 136.73 KB 35.92 KB 35.92 KB UMD_DEV
react-dom-server.browser.development.js 0.0% -0.0% 132.86 KB 132.86 KB 34.99 KB 34.99 KB NODE_DEV
ReactDOMServer-dev.js 0.0% -0.0% 134.95 KB 134.95 KB 34.61 KB 34.61 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 47.14 KB 47.14 KB 10.8 KB 10.8 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% -0.0% 134.8 KB 134.8 KB 35.54 KB 35.54 KB NODE_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.1 KB 1.1 KB 668 B 667 B NODE_PROD

react-events

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-events.development.js 0.0% +0.1% 1.59 KB 1.59 KB 687 B 688 B UMD_DEV
react-events.production.min.js 0.0% 🔺+0.2% 857 B 857 B 476 B 477 B UMD_PROD
react-events.development.js 0.0% +0.2% 1.4 KB 1.4 KB 625 B 626 B NODE_DEV
react-events-press.development.js +2.6% +0.6% 19.92 KB 20.45 KB 4.74 KB 4.77 KB UMD_DEV
react-events-press.production.min.js -0.1% 🔺+0.1% 7.76 KB 7.75 KB 2.64 KB 2.64 KB UMD_PROD
react-events-press.development.js +2.7% +0.6% 19.75 KB 20.28 KB 4.7 KB 4.73 KB NODE_DEV
react-events-press.production.min.js -0.1% 🔺+0.4% 7.59 KB 7.58 KB 2.58 KB 2.59 KB NODE_PROD
ReactEventsPress-dev.js +2.5% +0.6% 18.05 KB 18.51 KB 4 KB 4.03 KB FB_WWW_DEV
ReactEventsPress-prod.js 🔺+4.1% 🔺+1.8% 14.94 KB 15.55 KB 2.96 KB 3.01 KB FB_WWW_PROD
react-events-hover.development.js +2.8% +3.0% 7.92 KB 8.15 KB 1.99 KB 2.05 KB UMD_DEV
react-events-hover.production.min.js 🔺+0.9% 🔺+0.5% 3.45 KB 3.48 KB 1.27 KB 1.27 KB UMD_PROD
react-events-hover.development.js +2.9% +3.2% 7.75 KB 7.98 KB 1.95 KB 2.01 KB NODE_DEV
react-events-hover.production.min.js 🔺+1.0% 🔺+1.3% 3.28 KB 3.32 KB 1.22 KB 1.23 KB NODE_PROD
ReactEventsHover-dev.js +2.8% +3.1% 7.93 KB 8.15 KB 1.96 KB 2.02 KB FB_WWW_DEV
ReactEventsHover-prod.js 🔺+1.0% 🔺+0.8% 6.72 KB 6.79 KB 1.59 KB 1.6 KB FB_WWW_PROD
react-events-focus.development.js +4.3% +4.8% 3.8 KB 3.96 KB 1.18 KB 1.24 KB UMD_DEV
react-events-focus.production.min.js 🔺+0.8% 🔺+1.6% 1.71 KB 1.72 KB 760 B 772 B UMD_PROD
react-events-focus.development.js +4.6% +5.2% 3.63 KB 3.79 KB 1.13 KB 1.19 KB NODE_DEV
react-events-focus.production.min.js 🔺+0.9% 🔺+1.4% 1.54 KB 1.55 KB 693 B 703 B NODE_PROD
ReactEventsFocus-dev.js +4.6% +5.2% 3.54 KB 3.71 KB 1.11 KB 1.17 KB FB_WWW_DEV
ReactEventsFocus-prod.js 🔺+0.7% 🔺+1.3% 2.75 KB 2.77 KB 834 B 845 B FB_WWW_PROD
react-events-swipe.development.js +2.2% +2.6% 8.25 KB 8.43 KB 2.56 KB 2.63 KB UMD_DEV
react-events-swipe.production.min.js 🔺+0.4% 🔺+0.4% 3.45 KB 3.46 KB 1.6 KB 1.61 KB UMD_PROD
react-events-swipe.development.js +2.2% +2.6% 8.08 KB 8.26 KB 2.53 KB 2.59 KB NODE_DEV
react-events-swipe.production.min.js 🔺+0.4% 🔺+0.5% 3.29 KB 3.3 KB 1.54 KB 1.55 KB NODE_PROD
ReactEventsSwipe-dev.js +2.9% +3.6% 6.17 KB 6.36 KB 1.78 KB 1.84 KB FB_WWW_DEV
ReactEventsSwipe-prod.js 🔺+0.3% 🔺+1.0% 5.94 KB 5.96 KB 1.54 KB 1.55 KB FB_WWW_PROD
react-events-drag.development.js +2.5% +2.9% 7.77 KB 7.96 KB 2.43 KB 2.51 KB UMD_DEV
react-events-drag.production.min.js 🔺+0.9% 🔺+0.7% 3.3 KB 3.33 KB 1.5 KB 1.5 KB UMD_PROD
react-events-drag.development.js +2.6% +2.9% 7.6 KB 7.79 KB 2.4 KB 2.47 KB NODE_DEV
react-events-drag.production.min.js 🔺+1.0% 🔺+1.1% 3.13 KB 3.17 KB 1.43 KB 1.45 KB NODE_PROD
ReactEventsDrag-dev.js +3.3% +4.1% 5.85 KB 6.05 KB 1.69 KB 1.76 KB FB_WWW_DEV
ReactEventsDrag-prod.js 🔺+1.1% 🔺+1.6% 5.39 KB 5.45 KB 1.38 KB 1.41 KB FB_WWW_PROD

Generated by 🚫 dangerJS

@trueadm trueadm changed the title Event API: Redesign event responder instance propagation Experimental Event API: Redesign event responder propagation Apr 13, 2019
Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@trueadm trueadm merged commit 9ebe176 into facebook:master Apr 13, 2019
@trueadm trueadm deleted the event-dispatching-redesign branch April 13, 2019 19:37
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