Skip to content

Experimental Event API: Remove TouchHitTarget SSR logic to prevent issues with mouse events #15381

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

Merged
merged 1 commit into from
Apr 11, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 11, 2019

This PR removes affects the experimental event API and its behaviour when server side rendering TouchHitTargets. Specifically, it changes the rendering so that hit slop elements are no longer serialized in SSR output. Instead we rely the hydration logic for the TouchHitTarget to add in the hit slop element to the client. This change comes after internal discussions with @sebmarkbage and @necolas, where we agreed this was the right change for now; we can revisit this again in the future if needed.

This change fixes mouse events incorrectly firing before hydration has occurred. For example, if you have a <button> that had a TouchHitTarget on it, it would render with an inner absolutely positioned <div> that "expanded" the hit boundaries of its parent <button>. We then handle mouse and touch events in the event responders, allowing touch events to use the expanded boundary as intended and filtering out mouse events (as they shouldn't use the expanded boundaries). Unfortunately, as this logic of filtering only gets initialized upon hydration of a component, the incorrect behaviour happens with mouse events on SSR content before this fix.

Ref #15257

@sizebot
Copy link

sizebot commented Apr 11, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: c25c59c...609f1d7

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js 0.0% 0.0% 897.34 KB 897.34 KB 203.09 KB 203.09 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 105.46 KB 105.46 KB 34.17 KB 34.17 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 108.46 KB 108.46 KB 34.79 KB 34.79 KB UMD_PROFILING
react-dom.profiling.min.js 0.0% 0.0% 108.57 KB 108.57 KB 34.2 KB 34.2 KB NODE_PROFILING
ReactDOM-dev.js 0.0% 0.0% 918.17 KB 918.17 KB 203.34 KB 203.35 KB FB_WWW_DEV
react-dom-unstable-fire.development.js 0.0% 0.0% 897.66 KB 897.66 KB 203.22 KB 203.22 KB UMD_DEV
react-dom-unstable-fire.production.min.js 0.0% 0.0% 105.47 KB 105.47 KB 34.18 KB 34.18 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js 0.0% 0.0% 108.48 KB 108.48 KB 34.8 KB 34.8 KB UMD_PROFILING
react-dom-unstable-fire.development.js 0.0% 0.0% 892.29 KB 892.29 KB 201.67 KB 201.67 KB NODE_DEV
react-dom-unstable-fire.profiling.min.js 0.0% 0.0% 108.58 KB 108.58 KB 34.21 KB 34.21 KB NODE_PROFILING
ReactFire-dev.js 0.0% 0.0% 917.36 KB 917.36 KB 203.4 KB 203.4 KB FB_WWW_DEV
react-dom-unstable-new-scheduler.profiling.min.js 0.0% 0.0% 106.96 KB 106.96 KB 33.99 KB 33.99 KB NODE_PROFILING
ReactDOMNewScheduler-dev.js 0.0% 0.0% 918.2 KB 918.2 KB 203.35 KB 203.35 KB FB_WWW_DEV
ReactDOMNewScheduler-profiling.js 0.0% 0.0% 340 KB 340 KB 63.22 KB 63.22 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.52 KB 10.52 KB 3.89 KB 3.9 KB UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 54.01 KB 54.01 KB 14.96 KB 14.96 KB NODE_DEV
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-server.browser.development.js -0.1% -0.1% 137.02 KB 136.83 KB 36 KB 35.97 KB UMD_DEV
react-dom-server.browser.development.js -0.1% -0.1% 133.15 KB 132.96 KB 35.06 KB 35.03 KB NODE_DEV
ReactDOMServer-dev.js -0.3% -0.1% 135.53 KB 135.16 KB 34.76 KB 34.71 KB FB_WWW_DEV
ReactDOMServer-prod.js -1.9% -1.8% 48.04 KB 47.14 KB 11 KB 10.8 KB FB_WWW_PROD
react-dom-server.node.development.js -0.1% -0.1% 135.1 KB 134.9 KB 35.61 KB 35.58 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.21 KB 1.21 KB 706 B 707 B UMD_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 667 B 668 B NODE_PROD

Generated by 🚫 dangerJS

@trueadm trueadm requested review from necolas and sebmarkbage April 11, 2019 10:43
@trueadm trueadm merged commit a9eff32 into facebook:master Apr 11, 2019
@trueadm trueadm deleted the ssr-touch-hit-target-changes branch April 11, 2019 11:05
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.

We have to be a bit careful here because any differences in the DOM will cause layout computation thrash and recalcs even though there's no visual change.

With partial hydration there are many commits and not just one big one. The constant overhead of layout/recalc adds up multiple times over. Since this is expected to be in almost every subtree, that means that every partial hydration commit will recalc which it didn't before.

I wonder what we can minimize the cost of this. E.g. if it's absolutely positioned, and maybe we can use CSS containment, it won't recompute anything around it. Another technique is to use pointer-events: none in the initial HTML and then only change that style property on hydration.

// The logic that filters out mouse events from the hit slop
// is handled in event responder modules, which only get
// initialized upon hydration.
return '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't this cause a hydration warning now? Can you add back tests to ensure that SSR+hydration of a hit target actually still works?

This can also be problematic when this isn't the very last child of the parent. If there is a next sibling that's a div <Parent><HitTarget /><div /></Parent>, then we'll try to hydrate that sibling as the hit target instead of this one.

That's why I expected you to leave the div in place but without the top/left/bottom/right styles and then only add the styles in when we commit.

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.

5 participants