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

Refine event registration + event signatures #19244

Merged
merged 2 commits into from Jul 6, 2020

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Jul 2, 2020

Note: This PR was rebased on top of #19244.

In an attempt to break up the amount of changes in #19221, I decied to pull out the logic that was not strictly related to moving to the capture phase for events. This was mostly logic around handling event registration and the some of the clean up around the event workflow. This should hopefully make the other PR smaller and simpler to understand once it gets rebased on top of this PR.

@trueadm trueadm requested a review from gaearon July 2, 2020 21:22
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jul 2, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 2, 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 0709a3c:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Jul 2, 2020

Details of bundled changes.

Comparing: 65c1377...0709a3c

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.0% -0.0% 905.93 KB 905.59 KB 206.09 KB 206.09 KB NODE_DEV
ReactDOMForked-prod.js -0.2% -0.1% 388.82 KB 388.02 KB 72.55 KB 72.46 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% -0.0% 138.39 KB 138.39 KB 36.56 KB 36.56 KB NODE_DEV
react-dom.production.min.js -0.1% -0.3% 123.06 KB 122.89 KB 39.42 KB 39.3 KB NODE_PROD
ReactDOMForked-profiling.js -0.2% -0.1% 399.35 KB 398.55 KB 74.31 KB 74.21 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 144.55 KB 144.55 KB 36.75 KB 36.75 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 20.68 KB 20.68 KB 7.66 KB 7.66 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% -0.1% 10.35 KB 10.35 KB 4.07 KB 4.07 KB UMD_PROD
ReactDOMTesting-dev.js -0.0% -0.0% 934.63 KB 934.29 KB 209.86 KB 209.84 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% -0.0% 51.15 KB 51.15 KB 14.9 KB 14.9 KB NODE_DEV
ReactDOMTesting-prod.js -0.2% -0.1% 387.47 KB 386.57 KB 73.4 KB 73.31 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 5.61 KB 5.61 KB 1.87 KB 1.87 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.2 KB 10.2 KB 3.99 KB 3.99 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 5.36 KB 5.36 KB 1.81 KB 1.8 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.17 KB 1.17 KB 668 B 667 B NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 4.87 KB 4.87 KB 1.71 KB 1.7 KB NODE_DEV
react-dom.development.js -0.0% -0.0% 951.63 KB 951.27 KB 208.53 KB 208.52 KB UMD_DEV
react-dom.production.min.js -0.1% -0.1% 122.91 KB 122.73 KB 40.18 KB 40.13 KB UMD_PROD
react-dom.profiling.min.js -0.1% -0.2% 126.85 KB 126.68 KB 41.38 KB 41.3 KB UMD_PROFILING
ReactDOMForked-dev.js -0.0% 0.0% 966.78 KB 966.6 KB 216.21 KB 216.22 KB FB_WWW_DEV
react-dom.profiling.min.js -0.1% -0.3% 127.18 KB 127.01 KB 40.62 KB 40.51 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% -0.0% 20.34 KB 20.34 KB 7.52 KB 7.52 KB UMD_PROD
ReactDOM-dev.js -0.0% 0.0% 973.88 KB 973.71 KB 217.51 KB 217.52 KB FB_WWW_DEV
ReactDOM-prod.js -0.2% -0.1% 389.01 KB 388.21 KB 72.56 KB 72.47 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% -0.0% 137.12 KB 137.12 KB 36.31 KB 36.31 KB NODE_DEV
ReactDOM-profiling.js -0.2% -0.1% 399.54 KB 398.75 KB 74.32 KB 74.22 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% -0.0% 20.26 KB 20.26 KB 7.51 KB 7.51 KB NODE_PROD
ReactDOMServer-dev.js 0.0% -0.0% 142.62 KB 142.62 KB 36.25 KB 36.25 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% -0.0% 46.58 KB 46.58 KB 10.9 KB 10.9 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 55.53 KB 55.53 KB 15.37 KB 15.37 KB UMD_DEV

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

Size changes (experimental)

Generated by 🚫 dangerJS against 0709a3c

@sizebot
Copy link

sizebot commented Jul 2, 2020

Details of bundled changes.

Comparing: 65c1377...0709a3c

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.0% -0.0% 875.5 KB 875.16 KB 200.56 KB 200.56 KB NODE_DEV
ReactDOMForked-prod.js -0.2% -0.1% 400 KB 399.2 KB 74.13 KB 74.02 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% -0.0% 136.88 KB 136.88 KB 36.35 KB 36.35 KB NODE_DEV
react-dom.production.min.js -0.1% -0.2% 118.59 KB 118.42 KB 38.13 KB 38.04 KB NODE_PROD
ReactDOMForked-profiling.js -0.2% -0.1% 410.6 KB 409.8 KB 75.89 KB 75.79 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 142.96 KB 142.96 KB 36.55 KB 36.55 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 20.22 KB 20.22 KB 7.59 KB 7.59 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% -0.1% 10.34 KB 10.34 KB 4.06 KB 4.06 KB UMD_PROD
ReactDOMTesting-dev.js -0.0% -0.0% 962.65 KB 962.31 KB 215.75 KB 215.74 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% -0.0% 51.13 KB 51.13 KB 14.9 KB 14.89 KB NODE_DEV
ReactDOMTesting-prod.js -0.2% -0.1% 400.98 KB 400.15 KB 75.46 KB 75.38 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% -0.1% 10.19 KB 10.19 KB 3.98 KB 3.98 KB NODE_PROD
react-dom.development.js -0.0% -0.0% 919.85 KB 919.48 KB 202.94 KB 202.93 KB UMD_DEV
react-dom.production.min.js -0.2% -0.2% 118.51 KB 118.33 KB 38.86 KB 38.77 KB UMD_PROD
react-dom.profiling.min.js -0.1% -0.3% 122.4 KB 122.23 KB 40.03 KB 39.91 KB UMD_PROFILING
ReactDOMForked-dev.js -0.0% 0.0% 992.32 KB 992.15 KB 221.37 KB 221.39 KB FB_WWW_DEV
react-dom.profiling.min.js -0.1% -0.2% 122.66 KB 122.48 KB 39.3 KB 39.21 KB NODE_PROFILING
ReactDOM-dev.js -0.0% 0.0% 999.43 KB 999.26 KB 222.66 KB 222.68 KB FB_WWW_DEV
ReactDOM-prod.js -0.2% -0.1% 400.2 KB 399.4 KB 74.14 KB 74.03 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% -0.0% 135.61 KB 135.61 KB 36.1 KB 36.1 KB NODE_DEV
ReactDOM-profiling.js -0.2% -0.1% 410.79 KB 409.99 KB 75.91 KB 75.8 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% -0.0% 19.8 KB 19.8 KB 7.43 KB 7.43 KB NODE_PROD
ReactDOMServer-dev.js 0.0% -0.0% 146.66 KB 146.66 KB 37.25 KB 37.25 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% -0.0% 47.44 KB 47.44 KB 11.11 KB 11.11 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 55.52 KB 55.52 KB 15.36 KB 15.36 KB UMD_DEV

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

Size changes (stable)

Generated by 🚫 dangerJS against 0709a3c

@@ -904,17 +918,16 @@ export function accumulateEventTargetListeners(
if (eventListeners !== null) {
const listenersArr = Array.from(eventListeners);
const targetType = ((event.type: any): DOMTopLevelEventType);
const isCapturePhase = (event: any).eventPhase === 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a significant change. Instead of reading this from the event, we now pass it from outside based on whether it's in a list. Can you please explain why this is a refactoring rather than a semantic change? And what does it accomplish, exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess there are two things here to note:

  • This code is only used with createEventHandle logic, so this isn't that much of a significant change given we have no product code anywhere that uses this code path right now.
  • It avoids us having to rely on eventPhase which can change if you add a listener to a node and the listener triggers on it (which would mean eventPhase is 2, even if it were a capture phase). When we setup the listener we can add this information to the event flags as a detail, completely avoiding this check.

!isListeningToEvents(rootTargetDependencies, targetContainer))
topLevelType !== TOP_SELECTION_CHANGE &&
!eventListenerMap.has('onSelect') &&
!eventListenerMap.has('onSelectCapture')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain why this check is equivalent? It's not obvious to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather than going through all the dependencies one by one, we can instead check if we've registered onSelect or onSelectCapture. The dependencies are both the same, as we listen to the same events for both onSelect and onSelectCapture.

@trueadm trueadm merged commit 26071ab into facebook:master Jul 6, 2020
@trueadm trueadm deleted the refine-event-registration branch July 6, 2020 16:42
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