From 11f90049f1eacb5370e6e18be695bd5d839aace5 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 18 Nov 2019 11:44:01 +0000 Subject: [PATCH] [react-interactions] Rename Flare listeners prop to DEPRECATED_flareListeners Apply fixes Apply fixes --- .../ReactHooksInspection-test.internal.js | 2 +- ...DOMServerPartialHydration-test.internal.js | 8 +- .../react-dom/src/client/ReactDOMComponent.js | 10 +-- .../DOMEventResponderSystem-test.internal.js | 70 +++++++++-------- .../src/server/ReactPartialRenderer.js | 2 +- packages/react-dom/src/shared/DOMProperty.js | 10 ++- .../shared/ReactControlledValuePropTypes.js | 4 +- .../accessibility/src/FocusContain.js | 4 +- .../accessibility/src/FocusGroup.js | 5 +- .../accessibility/src/FocusTable.js | 2 +- .../events/docs/ContextMenu.md | 2 +- .../react-interactions/events/docs/Focus.md | 2 +- .../events/docs/FocusWithin.md | 2 +- .../react-interactions/events/docs/Hover.md | 2 +- .../react-interactions/events/docs/Press.md | 2 +- .../__tests__/ContextMenu-test.internal.js | 12 +-- .../src/dom/__tests__/Drag-test.internal.js | 6 +- .../src/dom/__tests__/Focus-test.internal.js | 14 ++-- .../__tests__/FocusWithin-test.internal.js | 10 +-- .../src/dom/__tests__/Hover-test.internal.js | 16 ++-- .../src/dom/__tests__/Input-test.internal.js | 76 ++++++++++++++----- .../dom/__tests__/Keyboard-test.internal.js | 16 ++-- .../MixedResponders-test-internal.js | 8 +- .../src/dom/__tests__/Press-test.internal.js | 30 ++++---- .../__tests__/PressLegacy-test.internal.js | 62 +++++++-------- .../src/dom/__tests__/Scroll-test.internal.js | 8 +- .../src/dom/__tests__/Tap-test.internal.js | 22 +++--- .../src/ReactFiberCommitWork.js | 14 ++-- .../src/ReactFiberCompleteWork.js | 23 +++--- .../react-reconciler/src/ReactFiberEvents.js | 2 +- .../src/__tests__/ReactScope-test.internal.js | 4 +- .../src/ReactTestHostConfig.js | 6 +- 32 files changed, 255 insertions(+), 201 deletions(-) diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.internal.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.internal.js index b449e0120d5fe..d56ca36a02f4f 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.internal.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.internal.js @@ -29,7 +29,7 @@ describe('ReactHooksInspection', () => { const listener = React.unstable_useResponder(TestResponder, { preventDefault: false, }); - return
Hello world
; + return
Hello world
; } let tree = ReactDebugTools.inspectHooks(Foo, {}); expect(tree).toEqual([ diff --git a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js index dc63c605d8201..e2ea6c0abf0e0 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js @@ -1892,7 +1892,7 @@ describe('ReactDOMServerPartialHydration', () => { function Button() { let listener = React.unstable_useResponder(TestResponder, {}); - return Click me; + return Click me; } function App() { @@ -2041,7 +2041,7 @@ describe('ReactDOMServerPartialHydration', () => { function Button() { let listener = React.unstable_useResponder(TestResponder, {}); - return Click me; + return Click me; } function Child() { @@ -2408,13 +2408,13 @@ describe('ReactDOMServerPartialHydration', () => { return (
- + {/* We suspend after to test what happens when we eager attach the listener. */} - + diff --git a/packages/react-dom/src/client/ReactDOMComponent.js b/packages/react-dom/src/client/ReactDOMComponent.js index 48b52eb195ea9..9b0f103abe771 100644 --- a/packages/react-dom/src/client/ReactDOMComponent.js +++ b/packages/react-dom/src/client/ReactDOMComponent.js @@ -103,7 +103,7 @@ const AUTOFOCUS = 'autoFocus'; const CHILDREN = 'children'; const STYLE = 'style'; const HTML = '__html'; -const LISTENERS = 'listeners'; +const DEPRECATED_flareListeners = 'DEPRECATED_flareListeners'; const {html: HTML_NAMESPACE} = Namespaces; @@ -346,7 +346,7 @@ function setInitialDOMProperties( setTextContent(domElement, '' + nextProp); } } else if ( - (enableFlareAPI && propKey === LISTENERS) || + (enableFlareAPI && propKey === DEPRECATED_flareListeners) || propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING ) { @@ -715,7 +715,7 @@ export function diffProperties( } else if (propKey === DANGEROUSLY_SET_INNER_HTML || propKey === CHILDREN) { // Noop. This is handled by the clear text mechanism. } else if ( - (enableFlareAPI && propKey === LISTENERS) || + (enableFlareAPI && propKey === DEPRECATED_flareListeners) || propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING ) { @@ -810,7 +810,7 @@ export function diffProperties( (updatePayload = updatePayload || []).push(propKey, '' + nextProp); } } else if ( - (enableFlareAPI && propKey === LISTENERS) || + (enableFlareAPI && propKey === DEPRECATED_flareListeners) || propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING ) { @@ -1065,7 +1065,7 @@ export function diffHydratedProperties( if (suppressHydrationWarning) { // Don't bother comparing. We're ignoring all these warnings. } else if ( - (enableFlareAPI && propKey === LISTENERS) || + (enableFlareAPI && propKey === DEPRECATED_flareListeners) || propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING || // Controlled attributes are not validated diff --git a/packages/react-dom/src/events/__tests__/DOMEventResponderSystem-test.internal.js b/packages/react-dom/src/events/__tests__/DOMEventResponderSystem-test.internal.js index 8496230041e55..a293814c25f06 100644 --- a/packages/react-dom/src/events/__tests__/DOMEventResponderSystem-test.internal.js +++ b/packages/react-dom/src/events/__tests__/DOMEventResponderSystem-test.internal.js @@ -96,7 +96,7 @@ describe('DOMEventResponderSystem', () => { function Test() { const listener = React.unstable_useResponder(TestResponder, {}); - return
Hello world
; + return
Hello world
; } const renderer = ReactTestRenderer.create(); expect(renderer).toMatchRenderedOutput(
Hello world
); @@ -108,7 +108,7 @@ describe('DOMEventResponderSystem', () => { function Test() { const listener = React.unstable_useResponder(TestResponder, {}); - return
Hello world
; + return
Hello world
; } const output = ReactDOMServer.renderToString(); expect(output).toBe(`
Hello world
`); @@ -127,7 +127,7 @@ describe('DOMEventResponderSystem', () => { return (
- + Hello world
@@ -165,7 +165,7 @@ describe('DOMEventResponderSystem', () => { const listener = React.unstable_useResponder(TestResponder, {}); return ( - ); @@ -225,7 +225,7 @@ describe('DOMEventResponderSystem', () => { const listener = React.unstable_useResponder(TestResponder, {}); return ( - ); @@ -270,7 +270,9 @@ describe('DOMEventResponderSystem', () => { const listener2 = React.unstable_useResponder(TestResponder, {}); return ( - ); @@ -304,8 +306,8 @@ describe('DOMEventResponderSystem', () => { const listener = React.unstable_useResponder(TestResponder, {}); return ( -
-
@@ -353,7 +355,9 @@ describe('DOMEventResponderSystem', () => { const listener2 = React.unstable_useResponder(TestResponderB, {}); return ( - ); @@ -374,8 +378,8 @@ describe('DOMEventResponderSystem', () => { const listener2 = React.unstable_useResponder(TestResponderB, {}); return ( -
-
@@ -406,8 +410,8 @@ describe('DOMEventResponderSystem', () => { const listener = React.unstable_useResponder(TestResponder, {name: 'A'}); const listener2 = React.unstable_useResponder(TestResponder, {name: 'B'}); return ( -
-
@@ -454,7 +458,7 @@ describe('DOMEventResponderSystem', () => { }); return ( - ); @@ -490,9 +494,9 @@ describe('DOMEventResponderSystem', () => { const listener = React.unstable_useResponder(TestResponder, {}); const listener2 = React.unstable_useResponder(TestResponder2, {}); if (toggle) { - return ; + return ; }; ReactDOM.render(, container); @@ -645,8 +649,8 @@ describe('DOMEventResponderSystem', () => { const listener2 = React.unstable_useResponder(TestResponderB, {}); return ( -
-
@@ -709,8 +713,8 @@ describe('DOMEventResponderSystem', () => { const listener2 = React.unstable_useResponder(TestResponderB, {}); return ( -
- +
+
); }; @@ -759,7 +763,7 @@ describe('DOMEventResponderSystem', () => { }); return ( - ); @@ -823,7 +827,7 @@ describe('DOMEventResponderSystem', () => { onFoo: e => eventLogs.push('hook'), }); - return ); @@ -927,7 +931,7 @@ describe('DOMEventResponderSystem', () => { const listener = React.unstable_useResponder(TestResponder, { onClick: logEvent, }); - return
); @@ -994,7 +998,7 @@ describe('DOMEventResponderSystem', () => { const Component = () => { const listener = React.unstable_useResponder(TestResponder, {}); return ( -
+
{ReactDOM.createPortal(
); diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index d777a398ec15a..d6310caffadf2 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -370,7 +370,7 @@ function createOpenTagMarkup( if (!hasOwnProperty.call(props, propKey)) { continue; } - if (enableFlareAPI && propKey === 'listeners') { + if (enableFlareAPI && propKey === 'DEPRECATED_flareListeners') { continue; } let propValue = props[propKey]; diff --git a/packages/react-dom/src/shared/DOMProperty.js b/packages/react-dom/src/shared/DOMProperty.js index bdfa10e14aacf..fe9c77d889fb7 100644 --- a/packages/react-dom/src/shared/DOMProperty.js +++ b/packages/react-dom/src/shared/DOMProperty.js @@ -8,6 +8,7 @@ */ import warning from 'shared/warning'; +import {enableFlareAPI} from 'shared/ReactFeatureFlags'; type PropertyType = 0 | 1 | 2 | 3 | 4 | 5 | 6; @@ -207,7 +208,7 @@ function PropertyInfoRecord( const properties = {}; // These props are reserved by React. They shouldn't be written to the DOM. -[ +const reservedProps = [ 'children', 'dangerouslySetInnerHTML', // TODO: This prevents the assignment of defaultValue to regular @@ -219,7 +220,12 @@ const properties = {}; 'suppressContentEditableWarning', 'suppressHydrationWarning', 'style', -].forEach(name => { +]; +if (enableFlareAPI) { + reservedProps.push('DEPRECATED_flareListeners'); +} + +reservedProps.forEach(name => { properties[name] = new PropertyInfoRecord( name, RESERVED, diff --git a/packages/react-dom/src/shared/ReactControlledValuePropTypes.js b/packages/react-dom/src/shared/ReactControlledValuePropTypes.js index b7096e2a3348b..dc2840c6aa966 100644 --- a/packages/react-dom/src/shared/ReactControlledValuePropTypes.js +++ b/packages/react-dom/src/shared/ReactControlledValuePropTypes.js @@ -36,7 +36,7 @@ if (__DEV__) { props.readOnly || props.disabled || props[propName] == null || - (enableFlareAPI && props.listeners) + (enableFlareAPI && props.DEPRECATED_flareListeners) ) { return null; } @@ -53,7 +53,7 @@ if (__DEV__) { props.readOnly || props.disabled || props[propName] == null || - (enableFlareAPI && props.listeners) + (enableFlareAPI && props.DEPRECATED_flareListeners) ) { return null; } diff --git a/packages/react-interactions/accessibility/src/FocusContain.js b/packages/react-interactions/accessibility/src/FocusContain.js index 61304364f108c..81e314eddcaae 100644 --- a/packages/react-interactions/accessibility/src/FocusContain.js +++ b/packages/react-interactions/accessibility/src/FocusContain.js @@ -82,7 +82,9 @@ export default function FocusContain({ ); return ( - + {children} ); diff --git a/packages/react-interactions/accessibility/src/FocusGroup.js b/packages/react-interactions/accessibility/src/FocusGroup.js index 28fc9fe9f05b0..c23d487ce93fe 100644 --- a/packages/react-interactions/accessibility/src/FocusGroup.js +++ b/packages/react-interactions/accessibility/src/FocusGroup.js @@ -217,7 +217,10 @@ export function createFocusGroup( }, }); return ( - + {children} ); diff --git a/packages/react-interactions/accessibility/src/FocusTable.js b/packages/react-interactions/accessibility/src/FocusTable.js index d77c778af1ed3..32696ed45c0d3 100644 --- a/packages/react-interactions/accessibility/src/FocusTable.js +++ b/packages/react-interactions/accessibility/src/FocusTable.js @@ -346,7 +346,7 @@ export function createFocusTable( }); return ( diff --git a/packages/react-interactions/events/docs/ContextMenu.md b/packages/react-interactions/events/docs/ContextMenu.md index 33b95c452be33..99e8f1a14099b 100644 --- a/packages/react-interactions/events/docs/ContextMenu.md +++ b/packages/react-interactions/events/docs/ContextMenu.md @@ -12,7 +12,7 @@ const Button = (props) => { }); return ( -
+
{props.children}
); diff --git a/packages/react-interactions/events/docs/Focus.md b/packages/react-interactions/events/docs/Focus.md index 47afc87240036..4d9f7e8b1cce8 100644 --- a/packages/react-interactions/events/docs/Focus.md +++ b/packages/react-interactions/events/docs/Focus.md @@ -19,7 +19,7 @@ const Button = (props) => { return (
); @@ -459,7 +459,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const listener = usePress({ onPressMove, }); - return
; + return
; }; ReactDOM.render(, container); ref.current.getBoundingClientRect = () => ({ @@ -521,7 +521,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { }); return (
-
+
); }; @@ -610,7 +610,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { onPressEnd: createEventHandler('onPressEnd'), pressRetentionOffset, }); - return
; + return
; }; ReactDOM.render(, container); @@ -756,7 +756,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { return (
{ onPressEnd: createEventHandler('outer: onPressEnd'), }); return ( -
+
); @@ -804,13 +804,13 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const Inner = () => { const listener = usePress({onPress}); - return
; + return
; }; const Outer = () => { const listener = usePress({onPress}); return ( -
+
); @@ -831,13 +831,13 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const Inner = () => { const listener = usePress({onPressStart, onPressEnd}); - return
; + return
; }; const Outer = () => { const listener = usePress({onPressStart, onPressEnd}); return ( -
+
); @@ -859,13 +859,13 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const Inner = () => { const listener = usePress({onPressChange}); - return
; + return
; }; const Outer = () => { const listener = usePress({onPressChange}); return ( -
+
); @@ -889,7 +889,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const Component = () => { const listener = usePress({onPress}); - return ; + return ; }; ReactDOM.render(, container); @@ -909,7 +909,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const Component = () => { const listener = usePress({onPress}); - return ; + return ; }; ReactDOM.render(, container); @@ -931,7 +931,7 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { const listener = usePress({onPress}); return ( -
); @@ -480,7 +480,7 @@ describeWithPointerEvent('Tap responder', hasPointerEvents => { ref = React.createRef(); const Component = () => { const listener = useTap({onTapUpdate}); - return
; + return
; }; ReactDOM.render(, container); document.elementFromPoint = () => ref.current; @@ -592,7 +592,7 @@ describeWithPointerEvent('Tap responder', hasPointerEvents => { onTapEnd: logger('end'), onTapCancel: logger('cancel'), }); - return
; + return
; }; ReactDOM.render(, container); document.elementFromPoint = () => ref.current; @@ -646,7 +646,7 @@ describeWithPointerEvent('Tap responder', hasPointerEvents => { const listener = useTap({onTapCancel, onTapUpdate}); return (
-
+
); @@ -800,7 +800,7 @@ describeWithPointerEvent('Tap responder', hasPointerEvents => { preventDefault: shouldPreventDefault, }); return ( -
+
); diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index 88a42db93dcaa..f365fb70ba685 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -124,7 +124,7 @@ import { } from './ReactHookEffectTags'; import {didWarnAboutReassigningProps} from './ReactFiberBeginWork'; import {runWithPriority, NormalPriority} from './SchedulerWithReactIntegration'; -import {updateEventListeners} from './ReactFiberEvents'; +import {updateLegacyEventListeners} from './ReactFiberEvents'; let didWarnAboutUndefinedSnapshotBeforeUpdate: Set | null = null; if (__DEV__) { @@ -1361,10 +1361,10 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void { ); } if (enableFlareAPI) { - const prevListeners = oldProps.listeners; - const nextListeners = newProps.listeners; + const prevListeners = oldProps.DEPRECATED_flareListeners; + const nextListeners = newProps.DEPRECATED_flareListeners; if (prevListeners !== nextListeners) { - updateEventListeners(nextListeners, finishedWork, null); + updateLegacyEventListeners(nextListeners, finishedWork, null); } } } @@ -1426,10 +1426,10 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void { if (enableFlareAPI) { const newProps = finishedWork.memoizedProps; const oldProps = current !== null ? current.memoizedProps : newProps; - const prevListeners = oldProps.listeners; - const nextListeners = newProps.listeners; + const prevListeners = oldProps.DEPRECATED_flareListeners; + const nextListeners = newProps.DEPRECATED_flareListeners; if (prevListeners !== nextListeners) { - updateEventListeners(nextListeners, finishedWork, null); + updateLegacyEventListeners(nextListeners, finishedWork, null); } } } diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.js b/packages/react-reconciler/src/ReactFiberCompleteWork.js index a8ea88728e21f..8f002d9f1cfaa 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.js @@ -128,7 +128,7 @@ import { import {createFundamentalStateInstance} from './ReactFiberFundamental'; import {Never} from './ReactFiberExpirationTime'; import {resetChildFibers} from './ReactChildFiber'; -import {updateEventListeners} from './ReactFiberEvents'; +import {updateLegacyEventListeners} from './ReactFiberEvents'; import {createScopeMethods} from './ReactFiberScope'; function markUpdate(workInProgress: Fiber) { @@ -686,8 +686,8 @@ function completeWork( ); if (enableFlareAPI) { - const prevListeners = current.memoizedProps.listeners; - const nextListeners = newProps.listeners; + const prevListeners = current.memoizedProps.DEPRECATED_flareListeners; + const nextListeners = newProps.DEPRECATED_flareListeners; if (prevListeners !== nextListeners) { markUpdate(workInProgress); } @@ -728,9 +728,9 @@ function completeWork( markUpdate(workInProgress); } if (enableFlareAPI) { - const listeners = newProps.listeners; + const listeners = newProps.DEPRECATED_flareListeners; if (listeners != null) { - updateEventListeners( + updateLegacyEventListeners( listeners, workInProgress, rootContainerInstance, @@ -752,9 +752,9 @@ function completeWork( workInProgress.stateNode = instance; if (enableFlareAPI) { - const listeners = newProps.listeners; + const listeners = newProps.DEPRECATED_flareListeners; if (listeners != null) { - updateEventListeners( + updateLegacyEventListeners( listeners, workInProgress, rootContainerInstance, @@ -1252,10 +1252,10 @@ function completeWork( workInProgress.stateNode = scopeInstance; scopeInstance.methods = createScopeMethods(type, scopeInstance); if (enableFlareAPI) { - const listeners = newProps.listeners; + const listeners = newProps.DEPRECATED_flareListeners; if (listeners != null) { const rootContainerInstance = getRootHostContainer(); - updateEventListeners( + updateLegacyEventListeners( listeners, workInProgress, rootContainerInstance, @@ -1268,8 +1268,9 @@ function completeWork( } } else { if (enableFlareAPI) { - const prevListeners = current.memoizedProps.listeners; - const nextListeners = newProps.listeners; + const prevListeners = + current.memoizedProps.DEPRECATED_flareListeners; + const nextListeners = newProps.DEPRECATED_flareListeners; if ( prevListeners !== nextListeners || workInProgress.ref !== null diff --git a/packages/react-reconciler/src/ReactFiberEvents.js b/packages/react-reconciler/src/ReactFiberEvents.js index af3b23b11a9b0..54f54ff02803c 100644 --- a/packages/react-reconciler/src/ReactFiberEvents.js +++ b/packages/react-reconciler/src/ReactFiberEvents.js @@ -146,7 +146,7 @@ function updateEventListener( } } -export function updateEventListeners( +export function updateLegacyEventListeners( listeners: any, fiber: Fiber, rootContainerInstance: null | Container, diff --git a/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js b/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js index e1cff6dc248f8..92ae0b829c1c6 100644 --- a/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js @@ -343,7 +343,7 @@ describe('ReactScope', () => { onKeyDown, }); return ( - +
); @@ -361,7 +361,7 @@ describe('ReactScope', () => { }); return (
- +
diff --git a/packages/react-test-renderer/src/ReactTestHostConfig.js b/packages/react-test-renderer/src/ReactTestHostConfig.js index 52848ad3aba2a..a3b8bff0f1339 100644 --- a/packages/react-test-renderer/src/ReactTestHostConfig.js +++ b/packages/react-test-renderer/src/ReactTestHostConfig.js @@ -149,11 +149,11 @@ export function createInstance( ): Instance { let propsToUse = props; if (enableFlareAPI) { - if (props.listeners != null) { - // We want to remove the "listeners" prop + if (props.DEPRECATED_flareListeners != null) { + // We want to remove the "DEPRECATED_flareListeners" prop // as we don't want it in the test renderer's // instance props. - const {listeners, ...otherProps} = props; // eslint-disable-line + const {DEPRECATED_flareListeners, ...otherProps} = props; // eslint-disable-line propsToUse = otherProps; } }