From d84332c4f7736a171febd230c2db4c3003feef0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Gonz=C3=A1lez?= Date: Thu, 5 Dec 2019 17:11:44 +0000 Subject: [PATCH] Revert "test this" This reverts commit fafc2e1889503083a9dcb4f8901fc143d423a19d. --- .../src/createSubscription.js | 20 ++-- packages/legacy-events/SyntheticEvent.js | 22 ++-- .../react-dom/src/client/ReactDOMSelect.js | 32 +++--- .../src/server/ReactPartialRenderer.js | 14 +-- .../src/server/ReactPartialRendererHooks.js | 20 ++-- .../src/shared/CSSPropertyOperations.js | 24 ++-- .../src/shared/ReactDOMInvalidARIAHook.js | 72 +++++------- .../shared/ReactDOMNullInputValuePropHook.js | 32 +++--- .../src/shared/ReactDOMUnknownPropertyHook.js | 36 +++--- .../src/NativeMethodsMixin.js | 34 +++--- .../react-native-renderer/src/ReactFabric.js | 12 +- .../src/ReactFabricHostConfig.js | 20 ++-- .../src/ReactNativeComponent.js | 34 +++--- .../src/ReactNativeFiberHostComponent.js | 10 +- .../src/ReactNativeRenderer.js | 12 +- .../react-reconciler/src/ReactChildFiber.js | 14 +-- .../src/ReactFiberBeginWork.js | 66 +++++------ .../src/ReactFiberReconciler.js | 14 +-- .../src/ReactShallowRenderer.js | 38 +++---- packages/react/src/ReactElement.js | 36 +++--- packages/react/src/ReactElementValidator.js | 106 ++++++++---------- 21 files changed, 287 insertions(+), 381 deletions(-) diff --git a/packages/create-subscription/src/createSubscription.js b/packages/create-subscription/src/createSubscription.js index b8fc7425dd..38febd017c 100644 --- a/packages/create-subscription/src/createSubscription.js +++ b/packages/create-subscription/src/createSubscription.js @@ -36,18 +36,14 @@ export function createSubscription( }> { const {getCurrentValue, subscribe} = config; - if (__DEV__) { - warningWithoutStack( - typeof getCurrentValue === 'function', - 'Subscription must specify a getCurrentValue function', - ); - } - if (__DEV__) { - warningWithoutStack( - typeof subscribe === 'function', - 'Subscription must specify a subscribe function', - ); - } + warningWithoutStack( + typeof getCurrentValue === 'function', + 'Subscription must specify a getCurrentValue function', + ); + warningWithoutStack( + typeof subscribe === 'function', + 'Subscription must specify a subscribe function', + ); type Props = { children: (value: Value) => React$Element, diff --git a/packages/legacy-events/SyntheticEvent.js b/packages/legacy-events/SyntheticEvent.js index 8dae2867ec..78812c15db 100644 --- a/packages/legacy-events/SyntheticEvent.js +++ b/packages/legacy-events/SyntheticEvent.js @@ -284,18 +284,16 @@ function getPooledWarningPropertyDefinition(propName, getVal) { function warn(action, result) { const warningCondition = false; - if (__DEV__) { - warningWithoutStack( - warningCondition, - "This synthetic event is reused for performance reasons. If you're seeing this, " + - "you're %s `%s` on a released/nullified synthetic event. %s. " + - 'If you must keep the original synthetic event around, use event.persist(). ' + - 'See https://fb.me/react-event-pooling for more information.', - action, - propName, - result, - ); - } + warningWithoutStack( + warningCondition, + "This synthetic event is reused for performance reasons. If you're seeing this, " + + "you're %s `%s` on a released/nullified synthetic event. %s. " + + 'If you must keep the original synthetic event around, use event.persist(). ' + + 'See https://fb.me/react-event-pooling for more information.', + action, + propName, + result, + ); } } diff --git a/packages/react-dom/src/client/ReactDOMSelect.js b/packages/react-dom/src/client/ReactDOMSelect.js index 48f9e2e04c..3bc982d77c 100644 --- a/packages/react-dom/src/client/ReactDOMSelect.js +++ b/packages/react-dom/src/client/ReactDOMSelect.js @@ -49,25 +49,21 @@ function checkSelectPropTypes(props) { } const isArray = Array.isArray(props[propName]); if (props.multiple && !isArray) { - if (__DEV__) { - warning( - false, - 'The `%s` prop supplied to must be an array if ' + + '`multiple` is true.%s', + propName, + getDeclarationErrorAddendum(), + ); } else if (!props.multiple && isArray) { - if (__DEV__) { - warning( - false, - 'The `%s` prop supplied to must be a scalar ' + + 'value if `multiple` is false.%s', + propName, + getDeclarationErrorAddendum(), + ); } } } diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index 3bb7692e4b..d6310caffa 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -687,14 +687,12 @@ function resolve( ); } } else { - if (__DEV__) { - warningWithoutStack( - false, - '%s.getChildContext(): childContextTypes must be defined in order to ' + - 'use getChildContext().', - getComponentName(Component) || 'Unknown', - ); - } + warningWithoutStack( + false, + '%s.getChildContext(): childContextTypes must be defined in order to ' + + 'use getChildContext().', + getComponentName(Component) || 'Unknown', + ); } } if (childContext) { diff --git a/packages/react-dom/src/server/ReactPartialRendererHooks.js b/packages/react-dom/src/server/ReactPartialRendererHooks.js index 58c386c1d6..d054caf530 100644 --- a/packages/react-dom/src/server/ReactPartialRendererHooks.js +++ b/packages/react-dom/src/server/ReactPartialRendererHooks.js @@ -393,17 +393,15 @@ export function useLayoutEffect( if (__DEV__) { currentHookNameInDev = 'useLayoutEffect'; } - if (__DEV__) { - warning( - false, - 'useLayoutEffect does nothing on the server, because its effect cannot ' + - "be encoded into the server renderer's output format. This will lead " + - 'to a mismatch between the initial, non-hydrated UI and the intended ' + - 'UI. To avoid this, useLayoutEffect should only be used in ' + - 'components that render exclusively on the client. ' + - 'See https://fb.me/react-uselayouteffect-ssr for common fixes.', - ); - } + warning( + false, + 'useLayoutEffect does nothing on the server, because its effect cannot ' + + "be encoded into the server renderer's output format. This will lead " + + 'to a mismatch between the initial, non-hydrated UI and the intended ' + + 'UI. To avoid this, useLayoutEffect should only be used in ' + + 'components that render exclusively on the client. ' + + 'See https://fb.me/react-uselayouteffect-ssr for common fixes.', + ); } function dispatchAction( diff --git a/packages/react-dom/src/shared/CSSPropertyOperations.js b/packages/react-dom/src/shared/CSSPropertyOperations.js index 8adcb8d9c0..38589fd19d 100644 --- a/packages/react-dom/src/shared/CSSPropertyOperations.js +++ b/packages/react-dom/src/shared/CSSPropertyOperations.js @@ -148,19 +148,17 @@ export function validateShorthandPropertyCollisionInDev( continue; } warnedAbout[warningKey] = true; - if (__DEV__) { - warning( - false, - '%s a style property during rerender (%s) when a ' + - 'conflicting property is set (%s) can lead to styling bugs. To ' + - "avoid this, don't mix shorthand and non-shorthand properties " + - 'for the same value; instead, replace the shorthand with ' + - 'separate values.', - isValueEmpty(styleUpdates[originalKey]) ? 'Removing' : 'Updating', - originalKey, - correctOriginalKey, - ); - } + warning( + false, + '%s a style property during rerender (%s) when a ' + + 'conflicting property is set (%s) can lead to styling bugs. To ' + + "avoid this, don't mix shorthand and non-shorthand properties " + + 'for the same value; instead, replace the shorthand with ' + + 'separate values.', + isValueEmpty(styleUpdates[originalKey]) ? 'Removing' : 'Updating', + originalKey, + correctOriginalKey, + ); } } } diff --git a/packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js b/packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js index e82f6485d4..59a7720c0a 100644 --- a/packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js +++ b/packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js @@ -31,26 +31,22 @@ function validateProperty(tagName, name) { // If this is an aria-* attribute, but is not listed in the known DOM // DOM properties, then it is an invalid aria-* attribute. if (correctName == null) { - if (__DEV__) { - warning( - false, - 'Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.', - name, - ); - } + warning( + false, + 'Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.', + name, + ); warnedProperties[name] = true; return true; } // aria-* attributes should be lowercase; suggest the lowercase version. if (name !== correctName) { - if (__DEV__) { - warning( - false, - 'Invalid ARIA attribute `%s`. Did you mean `%s`?', - name, - correctName, - ); - } + warning( + false, + 'Invalid ARIA attribute `%s`. Did you mean `%s`?', + name, + correctName, + ); warnedProperties[name] = true; return true; } @@ -70,14 +66,12 @@ function validateProperty(tagName, name) { } // aria-* attributes should be lowercase; suggest the lowercase version. if (name !== standardName) { - if (__DEV__) { - warning( - false, - 'Unknown ARIA attribute `%s`. Did you mean `%s`?', - name, - standardName, - ); - } + warning( + false, + 'Unknown ARIA attribute `%s`. Did you mean `%s`?', + name, + standardName, + ); warnedProperties[name] = true; return true; } @@ -101,25 +95,21 @@ function warnInvalidARIAProps(type, props) { .join(', '); if (invalidProps.length === 1) { - if (__DEV__) { - warning( - false, - 'Invalid aria prop %s on <%s> tag. ' + - 'For details, see https://fb.me/invalid-aria-prop', - unknownPropString, - type, - ); - } + warning( + false, + 'Invalid aria prop %s on <%s> tag. ' + + 'For details, see https://fb.me/invalid-aria-prop', + unknownPropString, + type, + ); } else if (invalidProps.length > 1) { - if (__DEV__) { - warning( - false, - 'Invalid aria props %s on <%s> tag. ' + - 'For details, see https://fb.me/invalid-aria-prop', - unknownPropString, - type, - ); - } + warning( + false, + 'Invalid aria props %s on <%s> tag. ' + + 'For details, see https://fb.me/invalid-aria-prop', + unknownPropString, + type, + ); } } diff --git a/packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js b/packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js index 5787ca0565..95f407b7da 100644 --- a/packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js +++ b/packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js @@ -17,25 +17,21 @@ export function validateProperties(type, props) { if (props != null && props.value === null && !didWarnValueNull) { didWarnValueNull = true; if (type === 'select' && props.multiple) { - if (__DEV__) { - warning( - false, - '`value` prop on `%s` should not be null. ' + - 'Consider using an empty array when `multiple` is set to `true` ' + - 'to clear the component or `undefined` for uncontrolled components.', - type, - ); - } + warning( + false, + '`value` prop on `%s` should not be null. ' + + 'Consider using an empty array when `multiple` is set to `true` ' + + 'to clear the component or `undefined` for uncontrolled components.', + type, + ); } else { - if (__DEV__) { - warning( - false, - '`value` prop on `%s` should not be null. ' + - 'Consider using an empty string to clear the component or `undefined` ' + - 'for uncontrolled components.', - type, - ); - } + warning( + false, + '`value` prop on `%s` should not be null. ' + + 'Consider using an empty string to clear the component or `undefined` ' + + 'for uncontrolled components.', + type, + ); } } } diff --git a/packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js b/packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js index 60bb3c49f5..3498111261 100644 --- a/packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js +++ b/packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js @@ -267,27 +267,23 @@ const warnUnknownProperties = function(type, props, canUseEventSystem) { .map(prop => '`' + prop + '`') .join(', '); if (unknownProps.length === 1) { - if (__DEV__) { - warning( - false, - 'Invalid value for prop %s on <%s> tag. Either remove it from the element, ' + - 'or pass a string or number value to keep it in the DOM. ' + - 'For details, see https://fb.me/react-attribute-behavior', - unknownPropString, - type, - ); - } + warning( + false, + 'Invalid value for prop %s on <%s> tag. Either remove it from the element, ' + + 'or pass a string or number value to keep it in the DOM. ' + + 'For details, see https://fb.me/react-attribute-behavior', + unknownPropString, + type, + ); } else if (unknownProps.length > 1) { - if (__DEV__) { - warning( - false, - 'Invalid values for props %s on <%s> tag. Either remove them from the element, ' + - 'or pass a string or number value to keep them in the DOM. ' + - 'For details, see https://fb.me/react-attribute-behavior', - unknownPropString, - type, - ); - } + warning( + false, + 'Invalid values for props %s on <%s> tag. Either remove them from the element, ' + + 'or pass a string or number value to keep them in the DOM. ' + + 'For details, see https://fb.me/react-attribute-behavior', + unknownPropString, + type, + ); } }; diff --git a/packages/react-native-renderer/src/NativeMethodsMixin.js b/packages/react-native-renderer/src/NativeMethodsMixin.js index 823ccd3fe5..27d928cee4 100644 --- a/packages/react-native-renderer/src/NativeMethodsMixin.js +++ b/packages/react-native-renderer/src/NativeMethodsMixin.js @@ -179,14 +179,12 @@ export default function( } if (maybeInstance.canonical) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: measureLayout on components using NativeMethodsMixin ' + - 'or ReactNative.NativeComponent is not currently supported in Fabric. ' + - 'measureLayout must be called on a native ref. Consider using forwardRef.', - ); - } + warningWithoutStack( + false, + 'Warning: measureLayout on components using NativeMethodsMixin ' + + 'or ReactNative.NativeComponent is not currently supported in Fabric. ' + + 'measureLayout must be called on a native ref. Consider using forwardRef.', + ); return; } else { let relativeNode; @@ -199,12 +197,10 @@ export default function( } if (relativeNode == null) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', - ); - } + warningWithoutStack( + false, + 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', + ); return; } @@ -247,12 +243,10 @@ export default function( } if (maybeInstance.canonical) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: setNativeProps is not currently supported in Fabric', - ); - } + warningWithoutStack( + false, + 'Warning: setNativeProps is not currently supported in Fabric', + ); return; } diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index d8e9ec6d58..ba4c6306b7 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -165,13 +165,11 @@ const ReactFabric: ReactFabricType = { handle._nativeTag == null || handle._internalInstanceHandle == null; if (invalid) { - if (__DEV__) { - warningWithoutStack( - !invalid, - "dispatchCommand was called with a ref that isn't a " + - 'native component. Use React.forwardRef to get access to the underlying native component', - ); - } + warningWithoutStack( + !invalid, + "dispatchCommand was called with a ref that isn't a " + + 'native component. Use React.forwardRef to get access to the underlying native component', + ); return; } diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 8c1afecaf8..0731867150 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -159,12 +159,10 @@ class ReactFabricHostComponent { typeof relativeToNativeNode === 'number' || !(relativeToNativeNode instanceof ReactFabricHostComponent) ) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: ref.measureLayout must be called with a ref to a native component.', - ); - } + warningWithoutStack( + false, + 'Warning: ref.measureLayout must be called with a ref to a native component.', + ); return; } @@ -178,12 +176,10 @@ class ReactFabricHostComponent { } setNativeProps(nativeProps: Object) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: setNativeProps is not currently supported in Fabric', - ); - } + warningWithoutStack( + false, + 'Warning: setNativeProps is not currently supported in Fabric', + ); return; } diff --git a/packages/react-native-renderer/src/ReactNativeComponent.js b/packages/react-native-renderer/src/ReactNativeComponent.js index d9eb73b4b8..52dfab9589 100644 --- a/packages/react-native-renderer/src/ReactNativeComponent.js +++ b/packages/react-native-renderer/src/ReactNativeComponent.js @@ -190,14 +190,12 @@ export default function( } if (maybeInstance.canonical) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: measureLayout on components using NativeMethodsMixin ' + - 'or ReactNative.NativeComponent is not currently supported in Fabric. ' + - 'measureLayout must be called on a native ref. Consider using forwardRef.', - ); - } + warningWithoutStack( + false, + 'Warning: measureLayout on components using NativeMethodsMixin ' + + 'or ReactNative.NativeComponent is not currently supported in Fabric. ' + + 'measureLayout must be called on a native ref. Consider using forwardRef.', + ); return; } else { let relativeNode; @@ -210,12 +208,10 @@ export default function( } if (relativeNode == null) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', - ); - } + warningWithoutStack( + false, + 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', + ); return; } @@ -258,12 +254,10 @@ export default function( } if (maybeInstance.canonical) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: setNativeProps is not currently supported in Fabric', - ); - } + warningWithoutStack( + false, + 'Warning: setNativeProps is not currently supported in Fabric', + ); return; } diff --git a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js index dfe9d12617..4bee7c7e10 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js +++ b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js @@ -85,12 +85,10 @@ class ReactNativeFiberHostComponent { } if (relativeNode == null) { - if (__DEV__) { - warningWithoutStack( - false, - 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', - ); - } + warningWithoutStack( + false, + 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', + ); return; } diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 55c34304f4..4e64cbc902 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -172,13 +172,11 @@ const ReactNativeRenderer: ReactNativeType = { dispatchCommand(handle: any, command: string, args: Array) { if (handle._nativeTag == null) { - if (__DEV__) { - warningWithoutStack( - handle._nativeTag != null, - "dispatchCommand was called with a ref that isn't a " + - 'native component. Use React.forwardRef to get access to the underlying native component', - ); - } + warningWithoutStack( + handle._nativeTag != null, + "dispatchCommand was called with a ref that isn't a " + + 'native component. Use React.forwardRef to get access to the underlying native component', + ); return; } diff --git a/packages/react-reconciler/src/ReactChildFiber.js b/packages/react-reconciler/src/ReactChildFiber.js index eb097266fb..fb94fe1df1 100644 --- a/packages/react-reconciler/src/ReactChildFiber.js +++ b/packages/react-reconciler/src/ReactChildFiber.js @@ -243,14 +243,12 @@ function warnOnFunctionType() { } ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; - if (__DEV__) { - warning( - false, - 'Functions are not valid as a React child. This may happen if ' + - 'you return a Component instead of from render. ' + - 'Or maybe you meant to call this function rather than return it.', - ); - } + warning( + false, + 'Functions are not valid as a React child. This may happen if ' + + 'you return a Component instead of from render. ' + + 'Or maybe you meant to call this function rather than return it.', + ); } // This wrapper function exists because I expect to clone the code in each path diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 0c78e10d46..1df6aa55bf 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -1398,13 +1398,11 @@ function mountIndeterminateComponent( function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { if (Component) { - if (__DEV__) { - warningWithoutStack( - !Component.childContextTypes, - '%s(...): childContextTypes cannot be defined on a function component.', - Component.displayName || Component.name || 'Component', - ); - } + warningWithoutStack( + !Component.childContextTypes, + '%s(...): childContextTypes cannot be defined on a function component.', + Component.displayName || Component.name || 'Component', + ); } if (workInProgress.ref !== null) { let info = ''; @@ -1420,15 +1418,13 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { } if (!didWarnAboutFunctionRefs[warningKey]) { didWarnAboutFunctionRefs[warningKey] = true; - if (__DEV__) { - warning( - false, - 'Function components cannot be given refs. ' + - 'Attempts to access this ref will fail. ' + - 'Did you mean to use React.forwardRef()?%s', - info, - ); - } + warning( + false, + 'Function components cannot be given refs. ' + + 'Attempts to access this ref will fail. ' + + 'Did you mean to use React.forwardRef()?%s', + info, + ); } } @@ -1439,14 +1435,12 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) { - if (__DEV__) { - warningWithoutStack( - false, - '%s: Support for defaultProps will be removed from function components ' + - 'in a future major release. Use JavaScript default parameters instead.', - componentName, - ); - } + warningWithoutStack( + false, + '%s: Support for defaultProps will be removed from function components ' + + 'in a future major release. Use JavaScript default parameters instead.', + componentName, + ); didWarnAboutDefaultPropsOnFunctionComponent[componentName] = true; } } @@ -1455,13 +1449,11 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) { - if (__DEV__) { - warningWithoutStack( - false, - '%s: Function components do not support getDerivedStateFromProps.', - componentName, - ); - } + warningWithoutStack( + false, + '%s: Function components do not support getDerivedStateFromProps.', + componentName, + ); didWarnAboutGetDerivedStateOnFunctionComponent[componentName] = true; } } @@ -1473,13 +1465,11 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutContextTypeOnFunctionComponent[componentName]) { - if (__DEV__) { - warningWithoutStack( - false, - '%s: Function components do not support contextType.', - componentName, - ); - } + warningWithoutStack( + false, + '%s: Function components do not support contextType.', + componentName, + ); didWarnAboutContextTypeOnFunctionComponent[componentName] = true; } } diff --git a/packages/react-reconciler/src/ReactFiberReconciler.js b/packages/react-reconciler/src/ReactFiberReconciler.js index e33a35c26f..6ebac0dace 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.js @@ -280,14 +280,12 @@ export function updateContainer( callback = callback === undefined ? null : callback; if (callback !== null) { - if (__DEV__) { - warningWithoutStack( - typeof callback === 'function', - 'render(...): Expected the last optional `callback` argument to be a ' + - 'function. Instead received: %s.', - callback, - ); - } + warningWithoutStack( + typeof callback === 'function', + 'render(...): Expected the last optional `callback` argument to be a ' + + 'function. Instead received: %s.', + callback, + ); update.callback = callback; } diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 8460e9912e..6da6467698 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -61,33 +61,29 @@ function areHookInputsEqual( prevDeps: Array | null, ) { if (prevDeps === null) { - if (__DEV__) { - warning( - false, - '%s received a final argument during this render, but not during ' + - 'the previous render. Even though the final argument is optional, ' + - 'its type cannot change between renders.', - currentHookNameInDev, - ); - } + warning( + false, + '%s received a final argument during this render, but not during ' + + 'the previous render. Even though the final argument is optional, ' + + 'its type cannot change between renders.', + currentHookNameInDev, + ); return false; } // Don't bother comparing lengths in prod because these arrays should be // passed inline. if (nextDeps.length !== prevDeps.length) { - if (__DEV__) { - warning( - false, - 'The final argument passed to %s changed size between renders. The ' + - 'order and size of this array must remain constant.\n\n' + - 'Previous: %s\n' + - 'Incoming: %s', - currentHookNameInDev, - `[${nextDeps.join(', ')}]`, - `[${prevDeps.join(', ')}]`, - ); - } + warning( + false, + 'The final argument passed to %s changed size between renders. The ' + + 'order and size of this array must remain constant.\n\n' + + 'Previous: %s\n' + + 'Incoming: %s', + currentHookNameInDev, + `[${nextDeps.join(', ')}]`, + `[${prevDeps.join(', ')}]`, + ); } for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) { if (is(nextDeps[i], prevDeps[i])) { diff --git a/packages/react/src/ReactElement.js b/packages/react/src/ReactElement.js index 70f82848dc..e900527b53 100644 --- a/packages/react/src/ReactElement.js +++ b/packages/react/src/ReactElement.js @@ -50,16 +50,14 @@ function defineKeyPropWarningGetter(props, displayName) { const warnAboutAccessingKey = function() { if (!specialPropKeyWarningShown) { specialPropKeyWarningShown = true; - if (__DEV__) { - warningWithoutStack( - false, - '%s: `key` is not a prop. Trying to access it will result ' + - 'in `undefined` being returned. If you need to access the same ' + - 'value within the child component, you should pass it as a different ' + - 'prop. (https://fb.me/react-special-props)', - displayName, - ); - } + warningWithoutStack( + false, + '%s: `key` is not a prop. Trying to access it will result ' + + 'in `undefined` being returned. If you need to access the same ' + + 'value within the child component, you should pass it as a different ' + + 'prop. (https://fb.me/react-special-props)', + displayName, + ); } }; warnAboutAccessingKey.isReactWarning = true; @@ -73,16 +71,14 @@ function defineRefPropWarningGetter(props, displayName) { const warnAboutAccessingRef = function() { if (!specialPropRefWarningShown) { specialPropRefWarningShown = true; - if (__DEV__) { - warningWithoutStack( - false, - '%s: `ref` is not a prop. Trying to access it will result ' + - 'in `undefined` being returned. If you need to access the same ' + - 'value within the child component, you should pass it as a different ' + - 'prop. (https://fb.me/react-special-props)', - displayName, - ); - } + warningWithoutStack( + false, + '%s: `ref` is not a prop. Trying to access it will result ' + + 'in `undefined` being returned. If you need to access the same ' + + 'value within the child component, you should pass it as a different ' + + 'prop. (https://fb.me/react-special-props)', + displayName, + ); } }; warnAboutAccessingRef.isReactWarning = true; diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index 0a2d0e5f8e..954d4e3be7 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -225,22 +225,18 @@ function validatePropTypes(element) { setCurrentlyValidatingElement(null); } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) { propTypesMisspellWarningShown = true; - if (__DEV__) { - warningWithoutStack( - false, - 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', - name || 'Unknown', - ); - } + warningWithoutStack( + false, + 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', + name || 'Unknown', + ); } if (typeof type.getDefaultProps === 'function') { - if (__DEV__) { - warningWithoutStack( - type.getDefaultProps.isReactClassApproved, - 'getDefaultProps is only used on classic React.createClass ' + - 'definitions. Use a static property named `defaultProps` instead.', - ); - } + warningWithoutStack( + type.getDefaultProps.isReactClassApproved, + 'getDefaultProps is only used on classic React.createClass ' + + 'definitions. Use a static property named `defaultProps` instead.', + ); } } @@ -255,22 +251,18 @@ function validateFragmentProps(fragment) { for (let i = 0; i < keys.length; i++) { const key = keys[i]; if (key !== 'children' && key !== 'key') { - if (__DEV__) { - warning( - false, - 'Invalid prop `%s` supplied to `React.Fragment`. ' + - 'React.Fragment can only have `key` and `children` props.', - key, - ); - } + warning( + false, + 'Invalid prop `%s` supplied to `React.Fragment`. ' + + 'React.Fragment can only have `key` and `children` props.', + key, + ); break; } } if (fragment.ref !== null) { - if (__DEV__) { - warning(false, 'Invalid attribute `ref` supplied to `React.Fragment`.'); - } + warning(false, 'Invalid attribute `ref` supplied to `React.Fragment`.'); } setCurrentlyValidatingElement(null); @@ -321,16 +313,14 @@ export function jsxWithValidation( typeString = typeof type; } - if (__DEV__) { - warning( - false, - 'React.jsx: type is invalid -- expected a string (for ' + - 'built-in components) or a class/function (for composite ' + - 'components) but got: %s.%s', - typeString, - info, - ); - } + warning( + false, + 'React.jsx: type is invalid -- expected a string (for ' + + 'built-in components) or a class/function (for composite ' + + 'components) but got: %s.%s', + typeString, + info, + ); } const element = jsxDEV(type, props, key, source, self); @@ -360,14 +350,12 @@ export function jsxWithValidation( Object.freeze(children); } } else { - if (__DEV__) { - warning( - false, - 'React.jsx: Static children should always be an array. ' + - 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + - 'Use the Babel transform instead.', - ); - } + warning( + false, + 'React.jsx: Static children should always be an array. ' + + 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + + 'Use the Babel transform instead.', + ); } } else { validateChildKeys(children, type); @@ -376,14 +364,12 @@ export function jsxWithValidation( } if (hasOwnProperty.call(props, 'key')) { - if (__DEV__) { - warning( - false, - 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' + - 'Explicitly pass a key after spreading props in your JSX call. ' + - 'E.g. ', - ); - } + warning( + false, + 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' + + 'Explicitly pass a key after spreading props in your JSX call. ' + + 'E.g. ', + ); } if (type === REACT_FRAGMENT_TYPE) { @@ -445,16 +431,14 @@ export function createElementWithValidation(type, props, children) { typeString = typeof type; } - if (__DEV__) { - warning( - false, - 'React.createElement: type is invalid -- expected a string (for ' + - 'built-in components) or a class/function (for composite ' + - 'components) but got: %s.%s', - typeString, - info, - ); - } + warning( + false, + 'React.createElement: type is invalid -- expected a string (for ' + + 'built-in components) or a class/function (for composite ' + + 'components) but got: %s.%s', + typeString, + info, + ); } const element = createElement.apply(this, arguments);