From a9eff329c6086cc12b7a61ff1b40ec9cc21c1c05 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 11 Apr 2019 12:05:26 +0100 Subject: [PATCH] Remove TouchHitTarget SSR logic to prevent issues with mouse events (#15381) --- .../src/server/ReactPartialRenderer.js | 27 ++++------- .../__tests__/TouchHitTarget-test.internal.js | 47 ++----------------- 2 files changed, 13 insertions(+), 61 deletions(-) diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index c493c0398ce5a..ce078dcb71779 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -1173,24 +1173,15 @@ class ReactDOMServerRenderer { elementType.$$typeof === REACT_EVENT_TARGET_TYPE && elementType.type === REACT_EVENT_TARGET_TOUCH_HIT ) { - const props = nextElement.props; - const bottom = props.bottom || 0; - const left = props.left || 0; - const right = props.right || 0; - const top = props.top || 0; - - if (bottom === 0 && left === 0 && right === 0 && top === 0) { - return ''; - } - let topString = top ? `-${top}px` : '0px'; - let leftString = left ? `-${left}px` : '0px'; - let rightString = right ? `-${right}px` : '0x'; - let bottomString = bottom ? `-${bottom}px` : '0px'; - - return ( - `
` - ); + // We do not render a hit slop element anymore. Instead we rely + // on hydration adding in the hit slop element. The previous + // logic had a bug where rendering a hit slop at SSR meant that + // mouse events incorrectly registered events on the hit slop + // even though it designed to be used for touch events only. + // The logic that filters out mouse events from the hit slop + // is handled in event responder modules, which only get + // initialized upon hydration. + return ''; } const nextChildren = toArray( ((nextChild: any): ReactElement).props.children, diff --git a/packages/react-events/src/__tests__/TouchHitTarget-test.internal.js b/packages/react-events/src/__tests__/TouchHitTarget-test.internal.js index e0bb517518be3..672e0b8bfc5ff 100644 --- a/packages/react-events/src/__tests__/TouchHitTarget-test.internal.js +++ b/packages/react-events/src/__tests__/TouchHitTarget-test.internal.js @@ -507,39 +507,6 @@ describe('TouchHitTarget', () => { ); }); - it('should hydrate TouchHitTarget hit slop elements correcty', () => { - const Test = () => ( - -
- -
-
- ); - - const container = document.createElement('div'); - container.innerHTML = '
'; - ReactDOM.hydrate(, container); - expect(Scheduler).toFlushWithoutYielding(); - expect(container.innerHTML).toBe('
'); - - const Test2 = () => ( - -
- -
-
- ); - - const container2 = document.createElement('div'); - container2.innerHTML = - '
'; - ReactDOM.hydrate(, container2); - expect(Scheduler).toFlushWithoutYielding(); - expect(container2.innerHTML).toBe( - '
', - ); - }); - it('should hydrate TouchHitTarget hit slop elements correcty and patch them', () => { const Test = () => ( @@ -586,7 +553,7 @@ describe('TouchHitTarget', () => { expect(output).toBe('
'); }); - it('should render a TouchHitTarget with hit slop values', () => { + it('should render a TouchHitTarget without hit slop values', () => { const Test = () => (
@@ -596,9 +563,7 @@ describe('TouchHitTarget', () => { ); let output = ReactDOMServer.renderToString(); - expect(output).toBe( - '
', - ); + expect(output).toBe('
'); const Test2 = () => ( @@ -609,9 +574,7 @@ describe('TouchHitTarget', () => { ); output = ReactDOMServer.renderToString(); - expect(output).toBe( - '
', - ); + expect(output).toBe('
'); const Test3 = () => ( @@ -622,9 +585,7 @@ describe('TouchHitTarget', () => { ); output = ReactDOMServer.renderToString(); - expect(output).toBe( - '
', - ); + expect(output).toBe('
'); }); }); });