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 full TouchHitTarget hit slop (experimental event API) to ReactDOM #15308

Merged
merged 13 commits into from
Apr 6, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 3, 2019

This PR is a complete replacement for the work suggested and originally started in #15261.

This PR aims add doing the following:

  • Support ReactDOM rendering <TouchHitTarget> elements. These elements can have optional numerical and nullable top, left, right and bottom props.
  • Support server-side rendering of these the hit targets along with their hit slop properties.
  • Support hydration from server-side rendered content for these hit targets.
  • Host configs now get additional methods: getEventTargetChildElement and commitEventTarget.
  • Tests mainly covering ReactDOM/ReactDOMServer support.

Furthermore, I found that we can't actually test the hit slop logic in JSDOM because it doesn't support a bunch of the DOM APIs that <TouchHitTarget> and respective event responders use. We'll need to come up with a different strategy for that, maybe @necolas has some ideas.

Ref #15257

Adds hydration support
@sizebot
Copy link

sizebot commented Apr 3, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: 49595e9...e5fe082

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.5% +0.6% 886.91 KB 891 KB 200.35 KB 201.47 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 105.58 KB 105.58 KB 34.19 KB 34.2 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 108.58 KB 108.59 KB 34.79 KB 34.8 KB UMD_PROFILING
react-dom.development.js +0.5% +0.6% 881.54 KB 885.63 KB 198.79 KB 199.92 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 105.56 KB 105.56 KB 33.64 KB 33.64 KB NODE_PROD
react-dom.profiling.min.js 0.0% 0.0% 108.67 KB 108.68 KB 34.23 KB 34.23 KB NODE_PROFILING
ReactDOM-dev.js +0.5% +0.5% 907.71 KB 911.84 KB 200.71 KB 201.82 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.8% 🔺+0.9% 333.43 KB 336.04 KB 61.34 KB 61.89 KB FB_WWW_PROD
ReactDOM-profiling.js +0.8% +0.9% 340.11 KB 342.71 KB 62.74 KB 63.28 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.5% +0.6% 887.23 KB 891.32 KB 200.49 KB 201.61 KB UMD_DEV
react-dom-unstable-fire.production.min.js 0.0% 0.0% 105.59 KB 105.59 KB 34.2 KB 34.2 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js 0.0% 0.0% 108.6 KB 108.6 KB 34.8 KB 34.81 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.5% +0.6% 881.86 KB 885.95 KB 198.93 KB 200.05 KB NODE_DEV
react-dom-unstable-fire.production.min.js 0.0% 0.0% 105.57 KB 105.58 KB 33.65 KB 33.65 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js 0.0% 0.0% 108.69 KB 108.69 KB 34.24 KB 34.24 KB NODE_PROFILING
ReactFire-dev.js +0.5% +0.6% 906.9 KB 911.03 KB 200.69 KB 201.79 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.8% 🔺+0.9% 322.08 KB 324.68 KB 59 KB 59.55 KB FB_WWW_PROD
ReactFire-profiling.js +0.8% +0.9% 328.71 KB 331.3 KB 60.4 KB 60.96 KB FB_WWW_PROFILING
react-dom-unstable-new-scheduler.development.js +0.5% +0.6% 880.12 KB 884.21 KB 198.24 KB 199.38 KB NODE_DEV
react-dom-unstable-new-scheduler.production.min.js 0.0% 0.0% 103.64 KB 103.65 KB 33.12 KB 33.12 KB NODE_PROD
react-dom-unstable-new-scheduler.profiling.min.js 0.0% -0.0% 106.99 KB 106.99 KB 34.01 KB 34.01 KB NODE_PROFILING
ReactDOMNewScheduler-dev.js +0.5% +0.5% 907.74 KB 911.87 KB 200.72 KB 201.82 KB FB_WWW_DEV
ReactDOMNewScheduler-prod.js 🔺+0.8% 🔺+0.9% 327.39 KB 329.99 KB 60.87 KB 61.41 KB FB_WWW_PROD
ReactDOMNewScheduler-profiling.js +0.8% +0.8% 333.14 KB 335.75 KB 61.96 KB 62.47 KB FB_WWW_PROFILING
react-dom-test-utils.development.js 0.0% -0.0% 52.68 KB 52.68 KB 14.33 KB 14.33 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.52 KB 10.52 KB 3.9 KB 3.89 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 52.41 KB 52.41 KB 14.26 KB 14.26 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.development.js 0.0% -0.0% 60.76 KB 60.76 KB 15.85 KB 15.85 KB UMD_DEV
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-unstable-native-dependencies.development.js 0.0% -0.0% 60.43 KB 60.43 KB 15.72 KB 15.72 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 10.42 KB 10.42 KB 3.57 KB 3.56 KB NODE_PROD
react-dom-server.browser.development.js +0.7% +0.7% 135.49 KB 136.44 KB 35.63 KB 35.88 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.24 KB 19.24 KB 7.24 KB 7.24 KB UMD_PROD
react-dom-server.browser.development.js +0.7% +0.7% 131.62 KB 132.57 KB 34.69 KB 34.94 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.17 KB 19.17 KB 7.23 KB 7.23 KB NODE_PROD
ReactDOMServer-dev.js +0.9% +0.7% 133.88 KB 135.04 KB 34.43 KB 34.69 KB FB_WWW_DEV
ReactDOMServer-prod.js 🔺+2.3% 🔺+2.2% 46.62 KB 47.7 KB 10.71 KB 10.95 KB FB_WWW_PROD
react-dom-server.node.development.js +0.7% +0.7% 133.56 KB 134.51 KB 35.24 KB 35.49 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 20.03 KB 20.03 KB 7.53 KB 7.53 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.66 KB 3.66 KB 1.45 KB 1.45 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 707 B 706 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.49 KB 3.49 KB 1.41 KB 1.41 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.05 KB 1.05 KB 638 B 637 B NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 3.74 KB 3.74 KB 1.43 KB 1.43 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-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.3% +0.3% 636.65 KB 638.73 KB 137.6 KB 137.95 KB UMD_DEV
react-art.production.min.js 0.0% -0.0% 97.31 KB 97.31 KB 29.78 KB 29.77 KB UMD_PROD
react-art.development.js +0.4% +0.3% 567.84 KB 569.94 KB 120.33 KB 120.67 KB NODE_DEV
react-art.production.min.js 0.0% -0.0% 62.3 KB 62.31 KB 19.05 KB 19.04 KB NODE_PROD
ReactART-dev.js +0.4% +0.4% 578.95 KB 581.18 KB 119.97 KB 120.4 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.1% 🔺+0.2% 198.31 KB 198.46 KB 33.58 KB 33.66 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.3% +0.3% 700.48 KB 702.62 KB 150.07 KB 150.46 KB RN_FB_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 246.82 KB 246.9 KB 43.18 KB 43.19 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 252.84 KB 252.91 KB 44.5 KB 44.51 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.3% +0.3% 700.39 KB 702.54 KB 150.04 KB 150.42 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 246.83 KB 246.91 KB 43.18 KB 43.19 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 252.86 KB 252.93 KB 44.5 KB 44.51 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.3% +0.3% 689.33 KB 691.47 KB 147.44 KB 147.83 KB RN_FB_DEV
ReactFabric-prod.js 0.0% 0.0% 240.14 KB 240.19 KB 41.93 KB 41.93 KB RN_FB_PROD
ReactFabric-profiling.js 0.0% 0.0% 245.44 KB 245.49 KB 43.26 KB 43.27 KB RN_FB_PROFILING
ReactFabric-dev.js +0.3% +0.3% 689.24 KB 691.38 KB 147.4 KB 147.78 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% 0.0% 240.15 KB 240.2 KB 41.92 KB 41.92 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 245.45 KB 245.5 KB 43.26 KB 43.27 KB RN_OSS_PROFILING

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.4% +0.4% 582.53 KB 584.78 KB 123.34 KB 123.83 KB UMD_DEV
react-test-renderer.production.min.js 0.0% 🔺+0.1% 63.61 KB 63.62 KB 19.45 KB 19.46 KB UMD_PROD
react-test-renderer.development.js +0.4% +0.4% 578.16 KB 580.41 KB 122.16 KB 122.69 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 0.0% 63.3 KB 63.32 KB 19.27 KB 19.27 KB NODE_PROD
ReactTestRenderer-dev.js +0.4% +0.5% 590.85 KB 593.08 KB 122.47 KB 123.03 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% 0.0% 39.85 KB 39.85 KB 9.96 KB 9.96 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.7 KB 11.7 KB 3.59 KB 3.59 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 34.08 KB 34.08 KB 8.58 KB 8.58 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.89 KB 11.89 KB 3.7 KB 3.7 KB NODE_PROD

react-noop-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-noop-renderer.development.js +1.1% +2.2% 34.65 KB 35.04 KB 8.51 KB 8.7 KB NODE_DEV
react-noop-renderer.production.min.js 🔺+1.3% 🔺+1.1% 10.29 KB 10.42 KB 3.4 KB 3.44 KB NODE_PROD
react-noop-renderer-persistent.development.js +1.1% +2.2% 34.76 KB 35.16 KB 8.53 KB 8.71 KB NODE_DEV
react-noop-renderer-persistent.production.min.js 🔺+1.3% 🔺+1.1% 10.31 KB 10.44 KB 3.41 KB 3.45 KB NODE_PROD
react-noop-renderer-server.development.js 0.0% -0.1% 1.83 KB 1.83 KB 877 B 876 B NODE_DEV
react-noop-renderer-server.production.min.js 0.0% -0.4% 813 B 813 B 492 B 490 B NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.3% +0.2% 571.53 KB 573.16 KB 119.94 KB 120.2 KB NODE_DEV
react-reconciler.production.min.js 0.0% 0.0% 63.3 KB 63.31 KB 18.82 KB 18.82 KB NODE_PROD
react-reconciler-persistent.development.js +0.3% +0.2% 569.42 KB 571.04 KB 119.07 KB 119.34 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 0.0% 63.31 KB 63.32 KB 18.82 KB 18.82 KB NODE_PROD
react-reconciler-reflection.development.js 0.0% -0.0% 17.15 KB 17.15 KB 5.21 KB 5.21 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.43 KB 2.43 KB 1.09 KB 1.09 KB NODE_PROD

Generated by 🚫 dangerJS

@trueadm trueadm requested a review from necolas April 3, 2019 17:41
@trueadm
Copy link
Contributor Author

trueadm commented Apr 3, 2019

The bundle size is interesting, although the non-min size goes up from 105.45 KB -> 105.52 KB, gzip actually goes down from 33.59 KB -> 33.56 KB. This doesn't seem like something I can get down, as I made a bunch of changes to places that can't DCE (switch cases that now contain EventTarget and also I do a null check on the stateNode in a bunch of places (because EventTarget fibers can have a null value for stateNode as an optimization path for when the hit slop doesn't need to be added)..

@panergongzi
Copy link

so good

let rightString = right ? `-${right}px;` : '';
let bottomString = bottom ? `-${bottom}px;` : '';

return `<div style="position:absolute;${topString}${leftString}${rightString}${bottomString}"></div>`;
Copy link
Contributor

@necolas necolas Apr 4, 2019

Choose a reason for hiding this comment

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

It's worth noting that this could result in an undesirable experience for mouse-based interactions if the client-side JS fix is unavailable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how we tackle that one. Maybe @sebmarkbage had some ideas. I think you can maybe get away using some clever pointer media queries in a stylesheet.

@trueadm
Copy link
Contributor Author

trueadm commented Apr 4, 2019

Build is failing because of some strange danger script error. Seems unrelated to this PR.

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

lgtm

if (childFiber === null) {
return false;
}
const parentFiber = childFiber.return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally we avoid traversing Fibers outside the reconciler but we already cheat this rule in the existing event system - for the same reasons as here. So this is ok.

@trueadm trueadm merged commit 4fbbae8 into facebook:master Apr 6, 2019
@trueadm trueadm deleted the add-touch-hit-target-impl branch April 6, 2019 06:51
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
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.

6 participants