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

Add container to event listener signature #18075

Merged
merged 1 commit into from
Feb 19, 2020

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Feb 19, 2020

Note: This PR is a pre-requisite for the modern root event system.

For the new event system that uses root containers to register nodes. For this to work, we need a sane way of knowing what the container is, so we can properly find ancestors.

We could use nativeEvent.currentTarget but that seems fragile, as the currentTarget can change when the event bubbles, or might not be there if we bypass native events entirely (if we ever decided to add onBeforeBlur to the plugin event system).

Instead, we can bind the container to the dispatch function, as we do with other arguments. This then allows us to know the container correctly in all cases. Furthermore, we pass this to the event replaying logic so it can properly replay the event with the correct container.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 19, 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.

@sizebot
Copy link

sizebot commented Feb 19, 2020

Details of bundled changes.

Comparing: f48a5e6...539baea

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-profiling.js +0.2% +0.1% 406.67 KB 407.29 KB 73.93 KB 74.01 KB FB_WWW_PROFILING
react-dom-testing.production.min.js 🔺+0.1% 0.0% 117.07 KB 117.15 KB 37.04 KB 37.04 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.72 KB 58.72 KB 15.35 KB 15.35 KB UMD_DEV
react-dom-testing.profiling.min.js +0.1% 0.0% 120.74 KB 120.83 KB 38.11 KB 38.13 KB NODE_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.24 KB 10.24 KB 3.47 KB 3.47 KB UMD_PROD
ReactTestUtils-dev.js 0.0% 0.0% 52.65 KB 52.66 KB 14.33 KB 14.33 KB FB_WWW_DEV
react-dom.development.js 0.0% 0.0% 967.74 KB 968.1 KB 217.3 KB 217.35 KB UMD_DEV
react-dom-server.browser.development.js 0.0% 0.0% 139.22 KB 139.22 KB 36.93 KB 36.93 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 115.95 KB 116.04 KB 37.21 KB 37.24 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 119.48 KB 119.56 KB 38.38 KB 38.4 KB UMD_PROFILING
ReactDOMTesting-dev.js +0.1% 0.0% 987.77 KB 988.39 KB 217.71 KB 217.78 KB FB_WWW_DEV
react-dom.development.js 0.0% 0.0% 961.82 KB 962.19 KB 215.67 KB 215.72 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.2% 🔺+0.1% 382.39 KB 383.02 KB 69.48 KB 69.56 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 135.16 KB 135.16 KB 35.9 KB 35.9 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 115.99 KB 116.08 KB 36.55 KB 36.56 KB NODE_PROD
react-dom-testing.development.js 0.0% 0.0% 965.09 KB 965.46 KB 216.3 KB 216.35 KB UMD_DEV
ReactDOMTesting-profiling.js +0.2% +0.1% 382.39 KB 383.02 KB 69.48 KB 69.56 KB FB_WWW_PROFILING
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.profiling.min.js +0.1% 0.0% 119.66 KB 119.75 KB 37.64 KB 37.66 KB NODE_PROFILING
react-dom-testing.production.min.js 🔺+0.1% 🔺+0.1% 116.99 KB 117.07 KB 37.7 KB 37.72 KB UMD_PROD
ReactDOM-dev.js +0.1% 0.0% 989.12 KB 989.75 KB 218.15 KB 218.21 KB FB_WWW_DEV
react-dom-testing.profiling.min.js +0.1% +0.1% 120.51 KB 120.59 KB 38.85 KB 38.88 KB UMD_PROFILING
ReactDOMServer-dev.js 0.0% -0.0% 140.24 KB 140.24 KB 35.5 KB 35.5 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.1% 395.33 KB 395.96 KB 71.84 KB 71.92 KB FB_WWW_PROD
react-dom-testing.development.js 0.0% 0.0% 959.17 KB 959.54 KB 214.67 KB 214.72 KB NODE_DEV
ReactDOMServer-prod.js 0.0% 0.0% 48.98 KB 48.98 KB 11.17 KB 11.18 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.7 KB 3.7 KB 1.49 KB 1.49 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 55.44 KB 55.45 KB 15.61 KB 15.61 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 9.98 KB 9.98 KB 3.37 KB 3.37 KB NODE_PROD
react-dom-test-utils.production.min.js 🔺+0.2% -0.1% 11.2 KB 11.21 KB 4.16 KB 4.15 KB UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 53.71 KB 53.72 KB 15.29 KB 15.29 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 136.27 KB 136.27 KB 36.13 KB 36.13 KB NODE_DEV
react-dom-test-utils.production.min.js 🔺+0.2% 🔺+0.1% 10.97 KB 10.99 KB 4.09 KB 4.1 KB NODE_PROD

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

Size changes (stable)

Generated by 🚫 dangerJS against 539baea

@sizebot
Copy link

sizebot commented Feb 19, 2020

Details of bundled changes.

Comparing: f48a5e6...539baea

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.1% 0.0% 123.72 KB 123.8 KB 38.72 KB 38.73 KB NODE_PROFILING
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
ReactDOM-dev.js +0.1% 0.0% 988.18 KB 988.8 KB 217.84 KB 217.9 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 55.46 KB 55.46 KB 15.61 KB 15.62 KB UMD_DEV
react-dom-testing.profiling.min.js +0.1% 0.0% 121.27 KB 121.35 KB 38.25 KB 38.26 KB NODE_PROFILING
react-dom-test-utils.production.min.js 🔺+0.2% -0.1% 11.21 KB 11.23 KB 4.17 KB 4.16 KB UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 53.73 KB 53.74 KB 15.29 KB 15.29 KB NODE_DEV
react-dom-server.browser.development.js 0.0% 0.0% 135.18 KB 135.18 KB 35.91 KB 35.91 KB NODE_DEV
react-dom-test-utils.production.min.js 🔺+0.2% 🔺+0.1% 10.99 KB 11 KB 4.1 KB 4.11 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% -0.0% 20.39 KB 20.39 KB 7.47 KB 7.47 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 967.76 KB 968.13 KB 217.32 KB 217.37 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 119.87 KB 119.96 KB 38.33 KB 38.34 KB UMD_PROD
ReactTestUtils-dev.js 0.0% 0.0% 52.65 KB 52.66 KB 14.33 KB 14.33 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.25 KB 10.25 KB 3.47 KB 3.47 KB UMD_PROD
react-dom.profiling.min.js +0.1% 0.0% 123.5 KB 123.59 KB 39.5 KB 39.51 KB UMD_PROFILING
react-dom.development.js 0.0% 0.0% 961.84 KB 962.21 KB 215.69 KB 215.74 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 119.93 KB 120.02 KB 37.57 KB 37.58 KB NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.99 KB 9.99 KB 3.38 KB 3.38 KB NODE_PROD
ReactDOM-prod.js 🔺+0.2% 🔺+0.1% 371.7 KB 372.33 KB 67.5 KB 67.59 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.1% 383.01 KB 383.63 KB 69.56 KB 69.65 KB FB_WWW_PROFILING
react-dom-testing.development.js 0.0% 0.0% 965.12 KB 965.48 KB 216.31 KB 216.36 KB UMD_DEV
react-dom-testing.production.min.js 🔺+0.1% 🔺+0.1% 117.52 KB 117.6 KB 37.86 KB 37.88 KB UMD_PROD
ReactDOMTesting-dev.js +0.1% 0.0% 987.78 KB 988.4 KB 217.72 KB 217.79 KB FB_WWW_DEV
react-dom-testing.profiling.min.js +0.1% 0.0% 121.04 KB 121.13 KB 39 KB 39.02 KB UMD_PROFILING
ReactDOMTesting-prod.js 🔺+0.2% 🔺+0.1% 370.09 KB 370.71 KB 67.39 KB 67.48 KB FB_WWW_PROD
react-dom-testing.development.js 0.0% 0.0% 959.2 KB 959.57 KB 214.68 KB 214.73 KB NODE_DEV
ReactDOMTesting-profiling.js +0.2% +0.1% 370.09 KB 370.71 KB 67.39 KB 67.48 KB FB_WWW_PROFILING
react-dom-server.node.development.js 0.0% -0.0% 136.29 KB 136.29 KB 36.14 KB 36.14 KB NODE_DEV
react-dom-testing.production.min.js 🔺+0.1% 0.0% 117.59 KB 117.68 KB 37.17 KB 37.18 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.0% 20.79 KB 20.79 KB 7.62 KB 7.62 KB NODE_PROD

Size changes (experimental)

Generated by 🚫 dangerJS against 539baea

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

The order of arguments across functions can be quite confusing 😅

@trueadm trueadm merged commit 1000f61 into facebook:master Feb 19, 2020
@trueadm trueadm deleted the roots-phase2 branch February 19, 2020 18:01
@@ -289,6 +325,7 @@ export function attemptToDispatchEvent(
topLevelType: DOMTopLevelEventType,
eventSystemFlags: EventSystemFlags,
nativeEvent: AnyNativeEvent,
container: Document | Element | Node,
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of the other signatures have it before nativeEvent so this was a bit confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the ones below don't. It would be nice to preserve a consistent order because it's easy to mix them up. Hopefully Flow would catch that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flow can catch it, and it did, because I've hacked this file abount so much in the last few days and it's saved my ass a bunch :)

I can refine the order in a follow up though, you're right, consistency helps here.

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.

5 participants