@samitouri / QOS-React-2 / commits / 9ac42dd074

Remove the condition argument from warning() (#17568)

* prep for codemod * prep warnings * rename lint rules * codemod for ifs * shim www functions * Handle more cases in the transform * Thanks De Morgan * Run the codemod * Delete the transform * Fix up confusing conditions manually * Fix up www shims to match expected API * Also check for low-pri warning in the lint rule

Laura buns committed Dec 11, 2019 at 03:28 UTC 9ac42dd074c42b66ecc0334b75200b1d2989f892
102 files changed +903 -1047
.eslintrc.js
+2 -1
@@ -92,7 +92,8 @@ module.exports = {
92 // the second argument of warning/invariant should be a literal string
93 'react-internal/no-primitive-constructors': ERROR,
94 'react-internal/no-to-warn-dev-within-to-throw': ERROR,
95 - 'react-internal/warning-and-invariant-args': ERROR,
95 + 'react-internal/invariant-args': ERROR,
96 + 'react-internal/warning-args': ERROR,
97 'react-internal/no-production-logging': ERROR,
98 },
99
packages/create-subscription/src/createSubscription.js
+8 -8
@@ -37,14 +37,14 @@ export function createSubscription<Property, Value>(
37 const {getCurrentValue, subscribe} = config;
38
39 if (__DEV__) {
40 - warningWithoutStack(
41 - typeof getCurrentValue === 'function',
42 - 'Subscription must specify a getCurrentValue function',
43 - );
44 - warningWithoutStack(
45 - typeof subscribe === 'function',
46 - 'Subscription must specify a subscribe function',
47 - );
40 + if (typeof getCurrentValue !== 'function') {
41 + warningWithoutStack(
42 + 'Subscription must specify a getCurrentValue function',
43 + );
44 + }
45 + if (typeof subscribe !== 'function') {
46 + warningWithoutStack('Subscription must specify a subscribe function');
47 + }
48 }
49
50 type Props = {
packages/legacy-events/EventPluginUtils.js
+9 -9
@@ -22,11 +22,12 @@ export function setComponentTree(
22 getInstanceFromNode = getInstanceFromNodeImpl;
23 getNodeFromInstance = getNodeFromInstanceImpl;
24 if (__DEV__) {
25 - warningWithoutStack(
26 - getNodeFromInstance && getInstanceFromNode,
27 - 'EventPluginUtils.setComponentTree(...): Injected ' +
28 - 'module is missing getNodeFromInstance or getInstanceFromNode.',
29 - );
25 + if (!getNodeFromInstance || !getInstanceFromNode) {
26 + warningWithoutStack(
27 + 'EventPluginUtils.setComponentTree(...): Injected ' +
28 + 'module is missing getNodeFromInstance or getInstanceFromNode.',
29 + );
30 + }
31 }
32 }
33
@@ -50,10 +51,9 @@ if (__DEV__) {
51 ? 1
52 : 0;
53
53 - warningWithoutStack(
54 - instancesIsArr === listenersIsArr && instancesLen === listenersLen,
55 - 'EventPluginUtils: Invalid `event`.',
56 - );
54 + if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
55 + warningWithoutStack('EventPluginUtils: Invalid `event`.');
56 + }
57 };
58 }
59
packages/legacy-events/EventPropagators.js
+3 -1
@@ -46,7 +46,9 @@ function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
46 */
47 function accumulateDirectionalDispatches(inst, phase, event) {
48 if (__DEV__) {
49 - warningWithoutStack(inst, 'Dispatching inst must not be null');
49 + if (!inst) {
50 + warningWithoutStack('Dispatching inst must not be null');
51 + }
52 }
53 const listener = listenerAtPhase(inst, event, phase);
54 if (listener) {
packages/legacy-events/ResponderTouchHistoryStore.js
+11 -11
@@ -95,13 +95,14 @@ function resetTouchRecord(touchRecord: TouchRecord, touch: Touch): void {
95 function getTouchIdentifier({identifier}: Touch): number {
96 invariant(identifier != null, 'Touch object is missing identifier.');
97 if (__DEV__) {
98 - warningWithoutStack(
99 - identifier <= MAX_TOUCH_BANK,
100 - 'Touch identifier %s is greater than maximum supported %s which causes ' +
101 - 'performance issues backfilling array locations for all of the indices.',
102 - identifier,
103 - MAX_TOUCH_BANK,
104 - );
98 + if (identifier > MAX_TOUCH_BANK) {
99 + warningWithoutStack(
100 + 'Touch identifier %s is greater than maximum supported %s which causes ' +
101 + 'performance issues backfilling array locations for all of the indices.',
102 + identifier,
103 + MAX_TOUCH_BANK,
104 + );
105 + }
106 }
107 return identifier;
108 }
@@ -200,10 +201,9 @@ const ResponderTouchHistoryStore = {
201 }
202 if (__DEV__) {
203 const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
203 - warningWithoutStack(
204 - activeRecord != null && activeRecord.touchActive,
205 - 'Cannot find single active touch.',
206 - );
204 + if (activeRecord == null || !activeRecord.touchActive) {
205 + warningWithoutStack('Cannot find single active touch.');
206 + }
207 }
208 }
209 }
packages/legacy-events/SyntheticEvent.js
-1
@@ -285,7 +285,6 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
285 function warn(action, result) {
286 if (__DEV__) {
287 warningWithoutStack(
288 - false,
288 "This synthetic event is reused for performance reasons. If you're seeing this, " +
289 "you're %s `%s` on a released/nullified synthetic event. %s. " +
290 'If you must keep the original synthetic event around, use event.persist(). ' +
packages/react-cache/src/ReactCache.js
+15 -12
@@ -64,18 +64,21 @@ function readContext(Context, observedBits) {
64
65 function identityHashFn(input) {
66 if (__DEV__) {
67 - warningWithoutStack(
68 - typeof input === 'string' ||
69 - typeof input === 'number' ||
70 - typeof input === 'boolean' ||
71 - input === undefined ||
72 - input === null,
73 - 'Invalid key type. Expected a string, number, symbol, or boolean, ' +
74 - 'but instead received: %s' +
75 - '\n\nTo use non-primitive values as keys, you must pass a hash ' +
76 - 'function as the second argument to createResource().',
77 - input,
78 - );
67 + if (
68 + typeof input !== 'string' &&
69 + typeof input !== 'number' &&
70 + typeof input !== 'boolean' &&
71 + input !== undefined &&
72 + input !== null
73 + ) {
74 + warningWithoutStack(
75 + 'Invalid key type. Expected a string, number, symbol, or boolean, ' +
76 + 'but instead received: %s' +
77 + '\n\nTo use non-primitive values as keys, you must pass a hash ' +
78 + 'function as the second argument to createResource().',
79 + input,
80 + );
81 + }
82 }
83 return input;
84 }
packages/react-dom/src/client/ReactDOM.js
-2
@@ -93,7 +93,6 @@ if (__DEV__) {
93 typeof Set.prototype.forEach !== 'function'
94 ) {
95 warningWithoutStack(
96 - false,
96 'React depends on Map and Set built-in types. Make sure that you load a ' +
97 'polyfill in older browsers. https://fb.me/react-polyfills',
98 );
@@ -146,7 +145,6 @@ const ReactDOM: Object = {
145 if (!didWarnAboutUnstableCreatePortal) {
146 didWarnAboutUnstableCreatePortal = true;
147 lowPriorityWarningWithoutStack(
149 - false,
148 'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
149 'and will be removed in React 17+. Update your code to use ' +
150 'ReactDOM.createPortal() instead. It has the exact same API, ' +
packages/react-dom/src/client/ReactDOMComponent.js
+9 -20
@@ -185,7 +185,6 @@ if (__DEV__) {
185 }
186 didWarnInvalidHydration = true;
187 warningWithoutStack(
188 - false,
188 'Text content did not match. Server: "%s" Client: "%s"',
189 normalizedServerText,
190 normalizedClientText,
@@ -211,7 +210,6 @@ if (__DEV__) {
210 }
211 didWarnInvalidHydration = true;
212 warningWithoutStack(
214 - false,
213 'Prop `%s` did not match. Server: %s Client: %s',
214 propName,
215 JSON.stringify(normalizedServerValue),
@@ -228,13 +226,12 @@ if (__DEV__) {
226 attributeNames.forEach(function(name) {
227 names.push(name);
228 });
231 - warningWithoutStack(false, 'Extra attributes from the server: %s', names);
229 + warningWithoutStack('Extra attributes from the server: %s', names);
230 };
231
232 warnForInvalidEventListener = function(registrationName, listener) {
233 if (listener === false) {
234 warning(
237 - false,
235 'Expected `%s` listener to be a function, instead got `false`.\n\n' +
236 'If you used to conditionally omit it with %s={condition && value}, ' +
237 'pass %s={condition ? value : undefined} instead.',
@@ -244,7 +241,6 @@ if (__DEV__) {
241 );
242 } else {
243 warning(
247 - false,
244 'Expected `%s` listener to be a function, instead got a value of `%s` type.',
245 registrationName,
246 typeof listener,
@@ -416,13 +412,14 @@ export function createElement(
412 isCustomComponentTag = isCustomComponent(type, props);
413 // Should this check be gated by parent namespace? Not sure we want to
414 // allow <SVG> or <mATH>.
419 - warning(
420 - isCustomComponentTag || type === type.toLowerCase(),
421 - '<%s /> is using incorrect casing. ' +
422 - 'Use PascalCase for React components, ' +
423 - 'or lowercase for HTML elements.',
424 - type,
425 - );
415 + if (!isCustomComponentTag && type !== type.toLowerCase()) {
416 + warning(
417 + '<%s /> is using incorrect casing. ' +
418 + 'Use PascalCase for React components, ' +
419 + 'or lowercase for HTML elements.',
420 + type,
421 + );
422 + }
423 }
424
425 if (type === 'script') {
@@ -432,7 +429,6 @@ export function createElement(
429 if (__DEV__) {
430 if (enableTrustedTypesIntegration && !didWarnScriptTags) {
431 warning(
435 - false,
432 'Encountered a script tag while rendering React component. ' +
433 'Scripts inside React components are never executed when rendering ' +
434 'on the client. Consider using template tag instead ' +
@@ -488,7 +484,6 @@ export function createElement(
484 ) {
485 warnedUnknownTags[type] = true;
486 warning(
491 - false,
487 'The tag <%s> is unrecognized in this browser. ' +
488 'If you meant to render a React component, start its name with ' +
489 'an uppercase letter.',
@@ -525,7 +520,6 @@ export function setInitialProperties(
520 (domElement: any).shadyRoot
521 ) {
522 warning(
528 - false,
523 '%s is using shady DOM. Using shady DOM with React can ' +
524 'cause things to break subtly.',
525 getCurrentFiberOwnerNameInDevOrNull() || 'A component',
@@ -926,7 +920,6 @@ export function diffHydratedProperties(
920 (domElement: any).shadyRoot
921 ) {
922 warning(
929 - false,
923 '%s is using shady DOM. Using shady DOM with React can ' +
924 'cause things to break subtly.',
925 getCurrentFiberOwnerNameInDevOrNull() || 'A component',
@@ -1219,7 +1212,6 @@ export function warnForDeletedHydratableElement(
1212 }
1213 didWarnInvalidHydration = true;
1214 warningWithoutStack(
1222 - false,
1215 'Did not expect server HTML to contain a <%s> in <%s>.',
1216 child.nodeName.toLowerCase(),
1217 parentNode.nodeName.toLowerCase(),
@@ -1237,7 +1229,6 @@ export function warnForDeletedHydratableText(
1229 }
1230 didWarnInvalidHydration = true;
1231 warningWithoutStack(
1240 - false,
1232 'Did not expect server HTML to contain the text node "%s" in <%s>.',
1233 child.nodeValue,
1234 parentNode.nodeName.toLowerCase(),
@@ -1256,7 +1247,6 @@ export function warnForInsertedHydratedElement(
1247 }
1248 didWarnInvalidHydration = true;
1249 warningWithoutStack(
1259 - false,
1250 'Expected server HTML to contain a matching <%s> in <%s>.',
1251 tag,
1252 parentNode.nodeName.toLowerCase(),
@@ -1281,7 +1271,6 @@ export function warnForInsertedHydratedText(
1271 }
1272 didWarnInvalidHydration = true;
1273 warningWithoutStack(
1284 - false,
1274 'Expected server HTML to contain a matching text node for "%s" in <%s>.',
1275 text,
1276 parentNode.nodeName.toLowerCase(),
packages/react-dom/src/client/ReactDOMInput.js
-4
@@ -80,7 +80,6 @@ export function initWrapperState(element: Element, props: Object) {
80 !didWarnCheckedDefaultChecked
81 ) {
82 warning(
83 - false,
83 '%s contains an input of type %s with both checked and defaultChecked props. ' +
84 'Input elements must be either controlled or uncontrolled ' +
85 '(specify either the checked prop, or the defaultChecked prop, but not ' +
@@ -98,7 +97,6 @@ export function initWrapperState(element: Element, props: Object) {
97 !didWarnValueDefaultValue
98 ) {
99 warning(
101 - false,
100 '%s contains an input of type %s with both value and defaultValue props. ' +
101 'Input elements must be either controlled or uncontrolled ' +
102 '(specify either the value prop, or the defaultValue prop, but not ' +
@@ -144,7 +142,6 @@ export function updateWrapper(element: Element, props: Object) {
142 !didWarnUncontrolledToControlled
143 ) {
144 warning(
147 - false,
145 'A component is changing an uncontrolled input of type %s to be controlled. ' +
146 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
147 'Decide between using a controlled or uncontrolled input ' +
@@ -159,7 +156,6 @@ export function updateWrapper(element: Element, props: Object) {
156 !didWarnControlledToUncontrolled
157 ) {
158 warning(
162 - false,
159 'A component is changing a controlled input of type %s to be uncontrolled. ' +
160 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
161 'Decide between using a controlled or uncontrolled input ' +
packages/react-dom/src/client/ReactDOMLegacy.js
+56 -53
@@ -55,13 +55,14 @@ if (__DEV__) {
55 container._reactRootContainer._internalRoot.current,
56 );
57 if (hostInstance) {
58 - warningWithoutStack(
59 - hostInstance.parentNode === container,
60 - 'render(...): It looks like the React-rendered content of this ' +
61 - 'container was removed without using React. This is not ' +
62 - 'supported and will cause errors. Instead, call ' +
63 - 'ReactDOM.unmountComponentAtNode to empty a container.',
64 - );
58 + if (hostInstance.parentNode !== container) {
59 + warningWithoutStack(
60 + 'render(...): It looks like the React-rendered content of this ' +
61 + 'container was removed without using React. This is not ' +
62 + 'supported and will cause errors. Instead, call ' +
63 + 'ReactDOM.unmountComponentAtNode to empty a container.',
64 + );
65 + }
66 }
67 }
68
@@ -69,24 +70,28 @@ if (__DEV__) {
70 const rootEl = getReactRootElementInContainer(container);
71 const hasNonRootReactChild = !!(rootEl && getInstanceFromNode(rootEl));
72
72 - warningWithoutStack(
73 - !hasNonRootReactChild || isRootRenderedBySomeReact,
74 - 'render(...): Replacing React-rendered children with a new root ' +
75 - 'component. If you intended to update the children of this node, ' +
76 - 'you should instead have the existing children update their state ' +
77 - 'and render the new components instead of calling ReactDOM.render.',
78 - );
73 + if (hasNonRootReactChild && !isRootRenderedBySomeReact) {
74 + warningWithoutStack(
75 + 'render(...): Replacing React-rendered children with a new root ' +
76 + 'component. If you intended to update the children of this node, ' +
77 + 'you should instead have the existing children update their state ' +
78 + 'and render the new components instead of calling ReactDOM.render.',
79 + );
80 + }
81
80 - warningWithoutStack(
81 - container.nodeType !== ELEMENT_NODE ||
82 - !((container: any): Element).tagName ||
83 - ((container: any): Element).tagName.toUpperCase() !== 'BODY',
84 - 'render(): Rendering components directly into document.body is ' +
85 - 'discouraged, since its children are often manipulated by third-party ' +
86 - 'scripts and browser extensions. This may lead to subtle ' +
87 - 'reconciliation issues. Try rendering into a container element created ' +
88 - 'for your app.',
89 - );
82 + if (
83 + container.nodeType === ELEMENT_NODE &&
84 + ((container: any): Element).tagName &&
85 + ((container: any): Element).tagName.toUpperCase() === 'BODY'
86 + ) {
87 + warningWithoutStack(
88 + 'render(): Rendering components directly into document.body is ' +
89 + 'discouraged, since its children are often manipulated by third-party ' +
90 + 'scripts and browser extensions. This may lead to subtle ' +
91 + 'reconciliation issues. Try rendering into a container element created ' +
92 + 'for your app.',
93 + );
94 + }
95 };
96 }
97
@@ -130,7 +135,6 @@ function legacyCreateRootFromDOMContainer(
135 ) {
136 warned = true;
137 warningWithoutStack(
133 - false,
138 'render(): Target node has markup rendered by React, but there ' +
139 'are unrelated nodes as well. This is most commonly caused by ' +
140 'white-space inserted around server-rendered markup.',
@@ -144,7 +148,6 @@ function legacyCreateRootFromDOMContainer(
148 if (shouldHydrate && !forceHydrate && !warnedAboutHydrateAPI) {
149 warnedAboutHydrateAPI = true;
150 lowPriorityWarningWithoutStack(
147 - false,
151 'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
152 'will stop working in React v17. Replace the ReactDOM.render() call ' +
153 'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
@@ -218,15 +221,16 @@ export function findDOMNode(
221 let owner = (ReactCurrentOwner.current: any);
222 if (owner !== null && owner.stateNode !== null) {
223 const warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
221 - warningWithoutStack(
222 - warnedAboutRefsInRender,
223 - '%s is accessing findDOMNode inside its render(). ' +
224 - 'render() should be a pure function of props and state. It should ' +
225 - 'never access something that requires stale data from the previous ' +
226 - 'render, such as refs. Move this logic to componentDidMount and ' +
227 - 'componentDidUpdate instead.',
228 - getComponentName(owner.type) || 'A component',
229 - );
224 + if (!warnedAboutRefsInRender) {
225 + warningWithoutStack(
226 + '%s is accessing findDOMNode inside its render(). ' +
227 + 'render() should be a pure function of props and state. It should ' +
228 + 'never access something that requires stale data from the previous ' +
229 + 'render, such as refs. Move this logic to componentDidMount and ' +
230 + 'componentDidUpdate instead.',
231 + getComponentName(owner.type) || 'A component',
232 + );
233 + }
234 owner.stateNode._warnedAboutRefsInRender = true;
235 }
236 }
@@ -257,7 +261,6 @@ export function hydrate(
261 container._reactRootContainer === undefined;
262 if (isModernRoot) {
263 warningWithoutStack(
260 - false,
264 'You are calling ReactDOM.hydrate() on a container that was previously ' +
265 'passed to ReactDOM.createRoot(). This is not supported. ' +
266 'Did you mean to call createRoot(container, {hydrate: true}).render(element)?',
@@ -289,7 +292,6 @@ export function render(
292 container._reactRootContainer === undefined;
293 if (isModernRoot) {
294 warningWithoutStack(
292 - false,
295 'You are calling ReactDOM.render() on a container that was previously ' +
296 'passed to ReactDOM.createRoot(). This is not supported. ' +
297 'Did you mean to call root.render(element)?',
@@ -340,7 +342,6 @@ export function unmountComponentAtNode(container: DOMContainer) {
342 container._reactRootContainer === undefined;
343 if (isModernRoot) {
344 warningWithoutStack(
343 - false,
345 'You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' +
346 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?',
347 );
@@ -351,11 +352,12 @@ export function unmountComponentAtNode(container: DOMContainer) {
352 if (__DEV__) {
353 const rootEl = getReactRootElementInContainer(container);
354 const renderedByDifferentReact = rootEl && !getInstanceFromNode(rootEl);
354 - warningWithoutStack(
355 - !renderedByDifferentReact,
356 - "unmountComponentAtNode(): The node you're attempting to unmount " +
357 - 'was rendered by another copy of React.',
358 - );
355 + if (renderedByDifferentReact) {
356 + warningWithoutStack(
357 + "unmountComponentAtNode(): The node you're attempting to unmount " +
358 + 'was rendered by another copy of React.',
359 + );
360 + }
361 }
362
363 // Unmount should not be batched.
@@ -379,16 +381,17 @@ export function unmountComponentAtNode(container: DOMContainer) {
381 isValidContainer(container.parentNode) &&
382 !!container.parentNode._reactRootContainer;
383
382 - warningWithoutStack(
383 - !hasNonRootReactChild,
384 - "unmountComponentAtNode(): The node you're attempting to unmount " +
385 - 'was rendered by React and is not a top-level container. %s',
386 - isContainerReactRoot
387 - ? 'You may have accidentally passed in a React root node instead ' +
388 - 'of its container.'
389 - : 'Instead, have the parent component update its state and ' +
390 - 'rerender in order to remove this component.',
391 - );
384 + if (hasNonRootReactChild) {
385 + warningWithoutStack(
386 + "unmountComponentAtNode(): The node you're attempting to unmount " +
387 + 'was rendered by React and is not a top-level container. %s',
388 + isContainerReactRoot
389 + ? 'You may have accidentally passed in a React root node instead ' +
390 + 'of its container.'
391 + : 'Instead, have the parent component update its state and ' +
392 + 'rerender in order to remove this component.',
393 + );
394 + }
395 }
396
397 return false;
packages/react-dom/src/client/ReactDOMOption.js
-2
@@ -59,7 +59,6 @@ export function validateProps(element: Element, props: Object) {
59 if (!didWarnInvalidChild) {
60 didWarnInvalidChild = true;
61 warning(
62 - false,
62 'Only strings and numbers are supported as <option> children.',
63 );
64 }
@@ -69,7 +68,6 @@ export function validateProps(element: Element, props: Object) {
68 // TODO: Remove support for `selected` in <option>.
69 if (props.selected != null && !didWarnSelectedSetOnOption) {
70 warning(
72 - false,
71 'Use the `defaultValue` or `value` props on <select> instead of ' +
72 'setting `selected` on <option>.',
73 );
packages/react-dom/src/client/ReactDOMRoot.js
+8 -9
@@ -156,13 +156,14 @@ export function warnOnInvalidCallback(
156 callerName: string,
157 ): void {
158 if (__DEV__) {
159 - warningWithoutStack(
160 - callback === null || typeof callback === 'function',
161 - '%s(...): Expected the last optional `callback` argument to be a ' +
162 - 'function. Instead received: %s.',
163 - callerName,
164 - callback,
165 - );
159 + if (callback !== null && typeof callback !== 'function') {
160 + warningWithoutStack(
161 + '%s(...): Expected the last optional `callback` argument to be a ' +
162 + 'function. Instead received: %s.',
163 + callerName,
164 + callback,
165 + );
166 + }
167 }
168 }
169
@@ -171,13 +172,11 @@ function warnIfReactDOMContainerInDEV(container) {
172 if (isContainerMarkedAsRoot(container)) {
173 if (container._reactRootContainer) {
174 warningWithoutStack(
174 - false,
175 'You are calling ReactDOM.createRoot() on a container that was previously ' +
176 'passed to ReactDOM.render(). This is not supported.',
177 );
178 } else {
179 warningWithoutStack(
180 - false,
180 'You are calling ReactDOM.createRoot() on a container that ' +
181 'has already been passed to createRoot() before. Instead, call ' +
182 'root.render() on the existing root instead if you want to update it.',
packages/react-dom/src/client/ReactDOMSelect.js
-3
@@ -51,7 +51,6 @@ function checkSelectPropTypes(props) {
51 const isArray = Array.isArray(props[propName]);
52 if (props.multiple && !isArray) {
53 warning(
54 - false,
54 'The `%s` prop supplied to <select> must be an array if ' +
55 '`multiple` is true.%s',
56 propName,
@@ -59,7 +58,6 @@ function checkSelectPropTypes(props) {
58 );
59 } else if (!props.multiple && isArray) {
60 warning(
62 - false,
61 'The `%s` prop supplied to <select> must be a scalar ' +
62 'value if `multiple` is false.%s',
63 propName,
@@ -159,7 +157,6 @@ export function initWrapperState(element: Element, props: Object) {
157 !didWarnValueDefaultValue
158 ) {
159 warning(
162 - false,
160 'Select elements must be either controlled or uncontrolled ' +
161 '(specify either the value prop, or the defaultValue prop, but not ' +
162 'both). Decide between using a controlled or uncontrolled select ' +
packages/react-dom/src/client/ReactDOMTextarea.js
-2
@@ -72,7 +72,6 @@ export function initWrapperState(element: Element, props: Object) {
72 !didWarnValDefaultVal
73 ) {
74 warning(
75 - false,
75 '%s contains a textarea with both value and defaultValue props. ' +
76 'Textarea elements must be either controlled or uncontrolled ' +
77 '(specify either the value prop, or the defaultValue prop, but not ' +
@@ -95,7 +94,6 @@ export function initWrapperState(element: Element, props: Object) {
94 if (children != null) {
95 if (__DEV__) {
96 warning(
98 - false,
97 'Use the `defaultValue` or `value` props instead of setting ' +
98 'children on <textarea>.',
99 );
packages/react-dom/src/client/setInnerHTML.js
+10 -9
@@ -32,15 +32,16 @@ const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(
32 if (enableTrustedTypesIntegration) {
33 // TODO: reconsider the text of this warning and when it should show
34 // before enabling the feature flag.
35 - warning(
36 - typeof trustedTypes === 'undefined',
37 - "Using 'dangerouslySetInnerHTML' in an svg element with " +
38 - 'Trusted Types enabled in an Internet Explorer will cause ' +
39 - 'the trusted value to be converted to string. Assigning string ' +
40 - "to 'innerHTML' will throw an error if Trusted Types are enforced. " +
41 - "You can try to wrap your svg element inside a div and use 'dangerouslySetInnerHTML' " +
42 - 'on the enclosing div instead.',
43 - );
35 + if (typeof trustedTypes !== 'undefined') {
36 + warning(
37 + "Using 'dangerouslySetInnerHTML' in an svg element with " +
38 + 'Trusted Types enabled in an Internet Explorer will cause ' +
39 + 'the trusted value to be converted to string. Assigning string ' +
40 + "to 'innerHTML' will throw an error if Trusted Types are enforced. " +
41 + "You can try to wrap your svg element inside a div and use 'dangerouslySetInnerHTML' " +
42 + 'on the enclosing div instead.',
43 + );
44 + }
45 }
46 }
47 if (!('innerHTML' in node)) {
packages/react-dom/src/client/validateDOMNesting.js
+5 -6
@@ -411,10 +411,11 @@ if (__DEV__) {
411 const parentTag = parentInfo && parentInfo.tag;
412
413 if (childText != null) {
414 - warningWithoutStack(
415 - childTag == null,
416 - 'validateDOMNesting: when childText is passed, childTag should be null',
417 - );
414 + if (childTag != null) {
415 + warningWithoutStack(
416 + 'validateDOMNesting: when childText is passed, childTag should be null',
417 + );
418 + }
419 childTag = '#text';
420 }
421
@@ -462,7 +463,6 @@ if (__DEV__) {
463 'the browser.';
464 }
465 warningWithoutStack(
465 - false,
466 'validateDOMNesting(...): %s cannot appear as a child of <%s>.%s%s%s',
467 tagDisplayName,
468 ancestorTag,
@@ -472,7 +472,6 @@ if (__DEV__) {
472 );
473 } else {
474 warningWithoutStack(
475 - false,
475 'validateDOMNesting(...): %s cannot appear as a descendant of ' +
476 '<%s>.%s',
477 tagDisplayName,
packages/react-dom/src/events/DOMEventResponderSystem.js
-1
@@ -235,7 +235,6 @@ function validateEventValue(eventValue: any): void {
235 const showWarning = name => {
236 if (__DEV__) {
237 warning(
238 - false,
238 '%s is not available on event objects created from event responder modules (React Flare). ' +
239 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.%s }`',
240 name,
packages/react-dom/src/events/SimpleEventPlugin.js
-1
@@ -343,7 +343,6 @@ const SimpleEventPlugin: PluginModule<MouseEvent> & {
343 if (__DEV__) {
344 if (knownHTMLTopLevelTypes.indexOf(topLevelType) === -1) {
345 warningWithoutStack(
346 - false,
346 'SimpleEventPlugin: Unhandled event type, `%s`. This warning ' +
347 'is likely caused by a bug in React. Please file an issue.',
348 topLevelType,
packages/react-dom/src/server/ReactPartialRenderer.js
+12 -31
@@ -271,7 +271,6 @@ function warnNoop(
271 }
272
273 warningWithoutStack(
274 - false,
274 '%s(...): Can only update a mounting component. ' +
275 'This usually means you called %s() outside componentWillMount() on the server. ' +
276 'This is a no-op.\n\nPlease check the code for the %s component.',
@@ -337,10 +336,7 @@ function flattenOptionChildren(children: mixed): ?string {
336 typeof child !== 'number'
337 ) {
338 didWarnInvalidOptionChildren = true;
340 - warning(
341 - false,
342 - 'Only strings and numbers are supported as <option> children.',
343 - );
339 + warning('Only strings and numbers are supported as <option> children.');
340 }
341 }
342 });
@@ -478,7 +474,6 @@ function resolve(
474 const componentName = getComponentName(Component) || 'Unknown';
475 if (!didWarnAboutUninitializedState[componentName]) {
476 warningWithoutStack(
481 - false,
477 '`%s` uses `getDerivedStateFromProps` but its initial state is ' +
478 '%s. This is not recommended. Instead, define the initial state by ' +
479 'assigning an object to `this.state` in the constructor of `%s`. ' +
@@ -503,7 +498,6 @@ function resolve(
498 const componentName = getComponentName(Component) || 'Unknown';
499 if (!didWarnAboutUndefinedDerivedState[componentName]) {
500 warningWithoutStack(
506 - false,
501 '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' +
502 'You have returned undefined.',
503 componentName,
@@ -527,7 +521,6 @@ function resolve(
521
522 if (!didWarnAboutBadClass[componentName]) {
523 warningWithoutStack(
530 - false,
524 "The <%s /> component appears to have a render method, but doesn't extend React.Component. " +
525 'This is likely to cause errors. Change %s to extend React.Component instead.',
526 componentName,
@@ -552,7 +545,6 @@ function resolve(
545 const componentName = getComponentName(Component) || 'Unknown';
546 if (!didWarnAboutModulePatternComponent[componentName]) {
547 warningWithoutStack(
555 - false,
548 'The <%s /> component appears to be a function component that returns a class instance. ' +
549 'Change %s to a class that extends React.Component instead. ' +
550 "If you can't use a class try assigning the prototype on the function as a workaround. " +
@@ -589,7 +581,6 @@ function resolve(
581
582 if (!didWarnAboutDeprecatedWillMount[componentName]) {
583 lowPriorityWarningWithoutStack(
592 - false,
584 // keep this warning in sync with ReactStrictModeWarning.js
585 'componentWillMount has been renamed, and is not recommended for use. ' +
586 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
@@ -666,7 +657,6 @@ function resolve(
657 let childContextTypes = Component.childContextTypes;
658 if (childContextTypes !== undefined) {
659 warningWithoutStack(
669 - false,
660 '%s uses the legacy childContextTypes API which is no longer supported. ' +
661 'Use React.createContext() instead.',
662 getComponentName(Component) || 'Unknown',
@@ -689,7 +679,6 @@ function resolve(
679 } else {
680 if (__DEV__) {
681 warningWithoutStack(
692 - false,
682 '%s.getChildContext(): childContextTypes must be defined in order to ' +
683 'use getChildContext().',
684 getComponentName(Component) || 'Unknown',
@@ -807,10 +796,9 @@ class ReactDOMServerRenderer {
796 popProvider<T>(provider: ReactProvider<T>): void {
797 const index = this.contextIndex;
798 if (__DEV__) {
810 - warningWithoutStack(
811 - index > -1 && provider === (this.contextProviderStack: any)[index],
812 - 'Unexpected pop.',
813 - );
799 + if (index < 0 || provider !== (this.contextProviderStack: any)[index]) {
800 + warningWithoutStack('Unexpected pop.');
801 + }
802 }
803
804 const context: ReactContext<any> = this.contextStack[index];
@@ -1182,7 +1170,6 @@ class ReactDOMServerRenderer {
1170 if (!hasWarnedAboutUsingContextAsConsumer) {
1171 hasWarnedAboutUsingContextAsConsumer = true;
1172 warning(
1185 - false,
1173 'Rendering <Context> directly is not supported and will be removed in ' +
1174 'a future major release. Did you mean to render <Context.Consumer> instead?',
1175 );
@@ -1363,13 +1350,14 @@ class ReactDOMServerRenderer {
1350 if (namespace === Namespaces.html) {
1351 // Should this check be gated by parent namespace? Not sure we want to
1352 // allow <SVG> or <mATH>.
1366 - warning(
1367 - tag === element.type,
1368 - '<%s /> is using incorrect casing. ' +
1369 - 'Use PascalCase for React components, ' +
1370 - 'or lowercase for HTML elements.',
1371 - element.type,
1372 - );
1353 + if (tag !== element.type) {
1354 + warning(
1355 + '<%s /> is using incorrect casing. ' +
1356 + 'Use PascalCase for React components, ' +
1357 + 'or lowercase for HTML elements.',
1358 + element.type,
1359 + );
1360 + }
1361 }
1362 }
1363
@@ -1386,7 +1374,6 @@ class ReactDOMServerRenderer {
1374 !didWarnDefaultChecked
1375 ) {
1376 warning(
1389 - false,
1377 '%s contains an input of type %s with both checked and defaultChecked props. ' +
1378 'Input elements must be either controlled or uncontrolled ' +
1379 '(specify either the checked prop, or the defaultChecked prop, but not ' +
@@ -1404,7 +1391,6 @@ class ReactDOMServerRenderer {
1391 !didWarnDefaultInputValue
1392 ) {
1393 warning(
1407 - false,
1394 '%s contains an input of type %s with both value and defaultValue props. ' +
1395 'Input elements must be either controlled or uncontrolled ' +
1396 '(specify either the value prop, or the defaultValue prop, but not ' +
@@ -1439,7 +1425,6 @@ class ReactDOMServerRenderer {
1425 !didWarnDefaultTextareaValue
1426 ) {
1427 warning(
1442 - false,
1428 'Textarea elements must be either controlled or uncontrolled ' +
1429 '(specify either the value prop, or the defaultValue prop, but not ' +
1430 'both). Decide between using a controlled or uncontrolled textarea ' +
@@ -1458,7 +1443,6 @@ class ReactDOMServerRenderer {
1443 if (textareaChildren != null) {
1444 if (__DEV__) {
1445 warning(
1461 - false,
1446 'Use the `defaultValue` or `value` props instead of setting ' +
1447 'children on <textarea>.',
1448 );
@@ -1499,14 +1483,12 @@ class ReactDOMServerRenderer {
1483 const isArray = Array.isArray(props[propName]);
1484 if (props.multiple && !isArray) {
1485 warning(
1502 - false,
1486 'The `%s` prop supplied to <select> must be an array if ' +
1487 '`multiple` is true.',
1488 propName,
1489 );
1490 } else if (!props.multiple && isArray) {
1491 warning(
1509 - false,
1492 'The `%s` prop supplied to <select> must be a scalar ' +
1493 'value if `multiple` is false.',
1494 propName,
@@ -1520,7 +1502,6 @@ class ReactDOMServerRenderer {
1502 !didWarnDefaultSelectValue
1503 ) {
1504 warning(
1523 - false,
1505 'Select elements must be either controlled or uncontrolled ' +
1506 '(specify either the value prop, or the defaultValue prop, but not ' +
1507 'both). Decide between using a controlled or uncontrolled select ' +
packages/react-dom/src/server/ReactPartialRendererContext.js
-3
@@ -113,7 +113,6 @@ export function processContext(
113 '}.';
114 }
115 warningWithoutStack(
116 - false,
116 '%s defines an invalid contextType. ' +
117 'contextType should point to the Context object returned by React.createContext().%s',
118 getComponentName(type) || 'Component',
@@ -130,7 +129,6 @@ export function processContext(
129 if (__DEV__) {
130 if (type.contextTypes) {
131 warningWithoutStack(
133 - false,
132 '%s uses the legacy contextTypes API which is no longer supported. ' +
133 'Use React.createContext() with static contextType instead.',
134 getComponentName(type) || 'Unknown',
@@ -152,7 +150,6 @@ export function processContext(
150 if (__DEV__) {
151 if (type.contextTypes) {
152 warningWithoutStack(
155 - false,
153 '%s uses the legacy contextTypes API which is no longer supported. ' +
154 'Use React.createContext() with React.useContext() instead.',
155 getComponentName(type) || 'Unknown',
packages/react-dom/src/server/ReactPartialRendererHooks.js
+16 -17
@@ -71,13 +71,14 @@ function resolveCurrentlyRenderingComponent(): Object {
71 'See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.',
72 );
73 if (__DEV__) {
74 - warning(
75 - !isInHookUserCodeInDev,
76 - 'Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' +
77 - 'You can only call Hooks at the top level of your React function. ' +
78 - 'For more information, see ' +
79 - 'https://fb.me/rules-of-hooks',
80 - );
74 + if (isInHookUserCodeInDev) {
75 + warning(
76 + 'Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' +
77 + 'You can only call Hooks at the top level of your React function. ' +
78 + 'For more information, see ' +
79 + 'https://fb.me/rules-of-hooks',
80 + );
81 + }
82 }
83 return currentlyRenderingComponent;
84 }
@@ -89,7 +90,6 @@ function areHookInputsEqual(
90 if (prevDeps === null) {
91 if (__DEV__) {
92 warning(
92 - false,
93 '%s received a final argument during this render, but not during ' +
94 'the previous render. Even though the final argument is optional, ' +
95 'its type cannot change between renders.',
@@ -104,7 +104,6 @@ function areHookInputsEqual(
104 // passed inline.
105 if (nextDeps.length !== prevDeps.length) {
106 warning(
107 - false,
107 'The final argument passed to %s changed size between renders. The ' +
108 'order and size of this array must remain constant.\n\n' +
109 'Previous: %s\n' +
@@ -223,13 +222,14 @@ function readContext<T>(
222 let threadID = currentThreadID;
223 validateContextBounds(context, threadID);
224 if (__DEV__) {
226 - warning(
227 - !isInHookUserCodeInDev,
228 - 'Context can only be read while React is rendering. ' +
229 - 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
230 - 'In function components, you can read it directly in the function body, but not ' +
231 - 'inside Hooks like useReducer() or useMemo().',
232 - );
225 + if (isInHookUserCodeInDev) {
226 + warning(
227 + 'Context can only be read while React is rendering. ' +
228 + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
229 + 'In function components, you can read it directly in the function body, but not ' +
230 + 'inside Hooks like useReducer() or useMemo().',
231 + );
232 + }
233 }
234 return context[threadID];
235 }
@@ -393,7 +393,6 @@ export function useLayoutEffect(
393 if (__DEV__) {
394 currentHookNameInDev = 'useLayoutEffect';
395 warning(
396 - false,
396 'useLayoutEffect does nothing on the server, because its effect cannot ' +
397 "be encoded into the server renderer's output format. This will lead " +
398 'to a mismatch between the initial, non-hydrated UI and the intended ' +
packages/react-dom/src/shared/CSSPropertyOperations.js
-1
@@ -150,7 +150,6 @@ export function validateShorthandPropertyCollisionInDev(
150 }
151 warnedAbout[warningKey] = true;
152 warning(
153 - false,
153 '%s a style property during rerender (%s) when a ' +
154 'conflicting property is set (%s) can lead to styling bugs. To ' +
155 "avoid this, don't mix shorthand and non-shorthand properties " +
packages/react-dom/src/shared/DOMProperty.js
+1 -1
@@ -85,7 +85,7 @@ export function isAttributeNameSafe(attributeName: string): boolean {
85 }
86 illegalAttributeNameCache[attributeName] = true;
87 if (__DEV__) {
88 - warning(false, 'Invalid attribute name: `%s`', attributeName);
88 + warning('Invalid attribute name: `%s`', attributeName);
89 }
90 return false;
91 }
packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js
-5
@@ -33,7 +33,6 @@ function validateProperty(tagName, name) {
33 // DOM properties, then it is an invalid aria-* attribute.
34 if (correctName == null) {
35 warning(
36 - false,
36 'Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.',
37 name,
38 );
@@ -43,7 +42,6 @@ function validateProperty(tagName, name) {
42 // aria-* attributes should be lowercase; suggest the lowercase version.
43 if (name !== correctName) {
44 warning(
46 - false,
45 'Invalid ARIA attribute `%s`. Did you mean `%s`?',
46 name,
47 correctName,
@@ -68,7 +66,6 @@ function validateProperty(tagName, name) {
66 // aria-* attributes should be lowercase; suggest the lowercase version.
67 if (name !== standardName) {
68 warning(
71 - false,
69 'Unknown ARIA attribute `%s`. Did you mean `%s`?',
70 name,
71 standardName,
@@ -99,7 +96,6 @@ function warnInvalidARIAProps(type, props) {
96
97 if (invalidProps.length === 1) {
98 warning(
102 - false,
99 'Invalid aria prop %s on <%s> tag. ' +
100 'For details, see https://fb.me/invalid-aria-prop',
101 unknownPropString,
@@ -107,7 +103,6 @@ function warnInvalidARIAProps(type, props) {
103 );
104 } else if (invalidProps.length > 1) {
105 warning(
110 - false,
106 'Invalid aria props %s on <%s> tag. ' +
107 'For details, see https://fb.me/invalid-aria-prop',
108 unknownPropString,
packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js
-2
@@ -19,7 +19,6 @@ export function validateProperties(type, props) {
19 didWarnValueNull = true;
20 if (type === 'select' && props.multiple) {
21 warning(
22 - false,
22 '`value` prop on `%s` should not be null. ' +
23 'Consider using an empty array when `multiple` is set to `true` ' +
24 'to clear the component or `undefined` for uncontrolled components.',
@@ -27,7 +26,6 @@ export function validateProperties(type, props) {
26 );
27 } else {
28 warning(
30 - false,
29 '`value` prop on `%s` should not be null. ' +
30 'Consider using an empty string to clear the component or `undefined` ' +
31 'for uncontrolled components.',
packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
-15
@@ -39,7 +39,6 @@ if (__DEV__) {
39 const lowerCasedName = name.toLowerCase();
40 if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
41 warning(
42 - false,
42 'React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' +
43 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' +
44 'are not needed/supported by React.',
@@ -60,7 +59,6 @@ if (__DEV__) {
59 : null;
60 if (registrationName != null) {
61 warning(
63 - false,
62 'Invalid event handler property `%s`. Did you mean `%s`?',
63 name,
64 registrationName,
@@ -70,7 +68,6 @@ if (__DEV__) {
68 }
69 if (EVENT_NAME_REGEX.test(name)) {
70 warning(
73 - false,
71 'Unknown event handler property `%s`. It will be ignored.',
72 name,
73 );
@@ -83,7 +80,6 @@ if (__DEV__) {
80 // out known bad ones like `onclick`. We can't suggest a specific replacement though.
81 if (INVALID_EVENT_NAME_REGEX.test(name)) {
82 warning(
86 - false,
83 'Invalid event handler property `%s`. ' +
84 'React events use the camelCase naming convention, for example `onClick`.',
85 name,
@@ -100,7 +96,6 @@ if (__DEV__) {
96
97 if (lowerCasedName === 'innerhtml') {
98 warning(
103 - false,
99 'Directly setting property `innerHTML` is not permitted. ' +
100 'For more information, lookup documentation on `dangerouslySetInnerHTML`.',
101 );
@@ -110,7 +105,6 @@ if (__DEV__) {
105
106 if (lowerCasedName === 'aria') {
107 warning(
113 - false,
108 'The `aria` attribute is reserved for future use in React. ' +
109 'Pass individual `aria-` attributes instead.',
110 );
@@ -125,7 +119,6 @@ if (__DEV__) {
119 typeof value !== 'string'
120 ) {
121 warning(
128 - false,
122 'Received a `%s` for a string attribute `is`. If this is expected, cast ' +
123 'the value to a string.',
124 typeof value,
@@ -136,7 +129,6 @@ if (__DEV__) {
129
130 if (typeof value === 'number' && isNaN(value)) {
131 warning(
139 - false,
132 'Received NaN for the `%s` attribute. If this is expected, cast ' +
133 'the value to a string.',
134 name,
@@ -153,7 +145,6 @@ if (__DEV__) {
145 const standardName = possibleStandardNames[lowerCasedName];
146 if (standardName !== name) {
147 warning(
156 - false,
148 'Invalid DOM property `%s`. Did you mean `%s`?',
149 name,
150 standardName,
@@ -165,7 +156,6 @@ if (__DEV__) {
156 // Unknown attributes should have lowercase casing since that's how they
157 // will be cased anyway with server rendering.
158 warning(
168 - false,
159 'React does not recognize the `%s` prop on a DOM element. If you ' +
160 'intentionally want it to appear in the DOM as a custom ' +
161 'attribute, spell it as lowercase `%s` instead. ' +
@@ -184,7 +174,6 @@ if (__DEV__) {
174 ) {
175 if (value) {
176 warning(
187 - false,
177 'Received `%s` for a non-boolean attribute `%s`.\n\n' +
178 'If you want to write it to the DOM, pass a string instead: ' +
179 '%s="%s" or %s={value.toString()}.',
@@ -196,7 +185,6 @@ if (__DEV__) {
185 );
186 } else {
187 warning(
199 - false,
188 'Received `%s` for a non-boolean attribute `%s`.\n\n' +
189 'If you want to write it to the DOM, pass a string instead: ' +
190 '%s="%s" or %s={value.toString()}.\n\n' +
@@ -234,7 +222,6 @@ if (__DEV__) {
222 propertyInfo.type === BOOLEAN
223 ) {
224 warning(
237 - false,
225 'Received the string `%s` for the boolean attribute `%s`. ' +
226 '%s ' +
227 'Did you mean %s={%s}?',
@@ -274,7 +261,6 @@ const warnUnknownProperties = function(type, props, canUseEventSystem) {
261 .join(', ');
262 if (unknownProps.length === 1) {
263 warning(
277 - false,
264 'Invalid value for prop %s on <%s> tag. Either remove it from the element, ' +
265 'or pass a string or number value to keep it in the DOM. ' +
266 'For details, see https://fb.me/react-attribute-behavior',
@@ -283,7 +269,6 @@ const warnUnknownProperties = function(type, props, canUseEventSystem) {
269 );
270 } else if (unknownProps.length > 1) {
271 warning(
286 - false,
272 'Invalid values for props %s on <%s> tag. Either remove them from the element, ' +
273 'or pass a string or number value to keep them in the DOM. ' +
274 'For details, see https://fb.me/react-attribute-behavior',
packages/react-dom/src/shared/assertValidProps.js
+12 -9
@@ -48,15 +48,18 @@ function assertValidProps(tag: string, props: ?Object) {
48 );
49 }
50 if (__DEV__) {
51 - warning(
52 - props.suppressContentEditableWarning ||
53 - !props.contentEditable ||
54 - props.children == null,
55 - 'A component is `contentEditable` and contains `children` managed by ' +
56 - 'React. It is now your responsibility to guarantee that none of ' +
57 - 'those nodes are unexpectedly modified or duplicated. This is ' +
58 - 'probably not intentional.',
59 - );
51 + if (
52 + !props.suppressContentEditableWarning &&
53 + props.contentEditable &&
54 + props.children != null
55 + ) {
56 + warning(
57 + 'A component is `contentEditable` and contains `children` managed by ' +
58 + 'React. It is now your responsibility to guarantee that none of ' +
59 + 'those nodes are unexpectedly modified or duplicated. This is ' +
60 + 'probably not intentional.',
61 + );
62 + }
63 }
64 invariant(
65 props.style == null || typeof props.style === 'object',
packages/react-dom/src/shared/sanitizeURL.js
-1
@@ -42,7 +42,6 @@ function sanitizeURL(url: string) {
42 if (!didWarn && isJavaScriptProtocol.test(url)) {
43 didWarn = true;
44 warning(
45 - false,
45 'A future version of React will block javascript: URLs as a security precaution. ' +
46 'Use event handlers instead if you can. If you need to generate unsafe HTML try ' +
47 'using dangerouslySetInnerHTML instead. React was passed %s.',
packages/react-dom/src/shared/warnValidStyle.js
+1 -9
@@ -36,7 +36,6 @@ if (__DEV__) {
36
37 warnedStyleNames[name] = true;
38 warning(
39 - false,
39 'Unsupported style property %s. Did you mean %s?',
40 name,
41 // As Andi Smith suggests
@@ -53,7 +52,6 @@ if (__DEV__) {
52
53 warnedStyleNames[name] = true;
54 warning(
56 - false,
55 'Unsupported vendor-prefixed style property %s. Did you mean %s?',
56 name,
57 name.charAt(0).toUpperCase() + name.slice(1),
@@ -67,7 +65,6 @@ if (__DEV__) {
65
66 warnedStyleValues[value] = true;
67 warning(
70 - false,
68 "Style property values shouldn't contain a semicolon. " +
69 'Try "%s: %s" instead.',
70 name,
@@ -81,11 +78,7 @@ if (__DEV__) {
78 }
79
80 warnedForNaNValue = true;
84 - warning(
85 - false,
86 - '`NaN` is an invalid value for the `%s` css style property.',
87 - name,
88 - );
81 + warning('`NaN` is an invalid value for the `%s` css style property.', name);
82 };
83
84 const warnStyleValueIsInfinity = function(name, value) {
@@ -95,7 +88,6 @@ if (__DEV__) {
88
89 warnedForInfinityValue = true;
90 warning(
98 - false,
91 '`Infinity` is an invalid value for the `%s` css style property.',
92 name,
93 );
packages/react-dom/src/test-utils/ReactTestUtils.js
-1
@@ -363,7 +363,6 @@ const ReactTestUtils = {
363 if (!hasWarnedAboutDeprecatedMockComponent) {
364 hasWarnedAboutDeprecatedMockComponent = true;
365 lowPriorityWarningWithoutStack(
366 - false,
366 'ReactTestUtils.mockComponent() is deprecated. ' +
367 'Use shallow rendering or jest.mock() instead.\n\n' +
368 'See https://fb.me/test-utils-mock-component for more information.',
packages/react-dom/src/test-utils/ReactTestUtilsAct.js
+7 -9
@@ -103,7 +103,6 @@ function act(callback: () => Thenable) {
103 if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
104 // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
105 warningWithoutStack(
106 - null,
106 'You seem to have overlapping act() calls, this is not supported. ' +
107 'Be sure to await previous act() calls before making a new one. ',
108 );
@@ -136,7 +135,6 @@ function act(callback: () => Thenable) {
135 .then(() => {
136 if (called === false) {
137 warningWithoutStack(
139 - null,
138 'You called act(async () => ...) without await. ' +
139 'This could lead to unexpected testing behaviour, interleaving multiple act ' +
140 'calls and mixing their scopes. You should - await act(async () => ...);',
@@ -183,12 +181,13 @@ function act(callback: () => Thenable) {
181 };
182 } else {
183 if (__DEV__) {
186 - warningWithoutStack(
187 - result === undefined,
188 - 'The callback passed to act(...) function ' +
189 - 'must return undefined, or a Promise. You returned %s',
190 - result,
191 - );
184 + if (result !== undefined) {
185 + warningWithoutStack(
186 + 'The callback passed to act(...) function ' +
187 + 'must return undefined, or a Promise. You returned %s',
188 + result,
189 + );
190 + }
191 }
192
193 // flush effects until none remain, and cleanup
@@ -212,7 +211,6 @@ function act(callback: () => Thenable) {
211 then(resolve: () => void) {
212 if (__DEV__) {
213 warningWithoutStack(
215 - false,
214 'Do not await the result of calling act(...) with sync logic, it is not a Promise.',
215 );
216 }
packages/react-flight/src/ReactFlightClientHostConfig.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -/* eslint-disable react-internal/warning-and-invariant-args */
10 +/* eslint-disable react-internal/invariant-args */
11
12 import invariant from 'shared/invariant';
13
packages/react-interactions/events/src/dom/Press.js
-2
@@ -74,7 +74,6 @@ function createGestureState(e: any, type: PressEventType): PressEvent {
74 // NO-OP, we should remove this in the future
75 if (__DEV__) {
76 warning(
77 - false,
77 'preventDefault is not available on event objects created from event responder modules (React Flare). ' +
78 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.preventDefault() }`',
79 );
@@ -84,7 +83,6 @@ function createGestureState(e: any, type: PressEventType): PressEvent {
83 // NO-OP, we should remove this in the future
84 if (__DEV__) {
85 warning(
87 - false,
86 'stopPropagation is not available on event objects created from event responder modules (React Flare). ' +
87 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.stopPropagation() }`',
88 );
packages/react-interactions/events/src/dom/PressLegacy.js
-1
@@ -207,7 +207,6 @@ function createPressEvent(
207 // NO-OP, we should remove this in the future
208 if (__DEV__) {
209 warning(
210 - false,
210 'stopPropagation is not available on event objects created from event responder modules (React Flare). ' +
211 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.stopPropagation() }`',
212 );
packages/react-is/src/ReactIs.js
-1
@@ -89,7 +89,6 @@ export function isAsyncMode(object: any) {
89 if (!hasWarnedAboutDeprecatedIsAsyncMode) {
90 hasWarnedAboutDeprecatedIsAsyncMode = true;
91 lowPriorityWarningWithoutStack(
92 - false,
92 'The ReactIs.isAsyncMode() alias has been deprecated, ' +
93 'and will be removed in React 17+. Update your code to use ' +
94 'ReactIs.isConcurrentMode() instead. It has the exact same API.',
packages/react-native-renderer/src/NativeMethodsMixin.js
-3
@@ -181,7 +181,6 @@ export default function(
181 if (maybeInstance.canonical) {
182 if (__DEV__) {
183 warningWithoutStack(
184 - false,
184 'Warning: measureLayout on components using NativeMethodsMixin ' +
185 'or ReactNative.NativeComponent is not currently supported in Fabric. ' +
186 'measureLayout must be called on a native ref. Consider using forwardRef.',
@@ -201,7 +200,6 @@ export default function(
200 if (relativeNode == null) {
201 if (__DEV__) {
202 warningWithoutStack(
204 - false,
203 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.',
204 );
205 }
@@ -249,7 +247,6 @@ export default function(
247 if (maybeInstance.canonical) {
248 if (__DEV__) {
249 warningWithoutStack(
252 - false,
250 'Warning: setNativeProps is not currently supported in Fabric',
251 );
252 }
packages/react-native-renderer/src/ReactFabric.js
+26 -23
@@ -49,15 +49,16 @@ function findHostInstance_DEPRECATED(
49 if (__DEV__) {
50 const owner = ReactCurrentOwner.current;
51 if (owner !== null && owner.stateNode !== null) {
52 - warningWithoutStack(
53 - owner.stateNode._warnedAboutRefsInRender,
54 - '%s is accessing findNodeHandle inside its render(). ' +
55 - 'render() should be a pure function of props and state. It should ' +
56 - 'never access something that requires stale data from the previous ' +
57 - 'render, such as refs. Move this logic to componentDidMount and ' +
58 - 'componentDidUpdate instead.',
59 - getComponentName(owner.type) || 'A component',
60 - );
52 + if (!owner.stateNode._warnedAboutRefsInRender) {
53 + warningWithoutStack(
54 + '%s is accessing findNodeHandle inside its render(). ' +
55 + 'render() should be a pure function of props and state. It should ' +
56 + 'never access something that requires stale data from the previous ' +
57 + 'render, such as refs. Move this logic to componentDidMount and ' +
58 + 'componentDidUpdate instead.',
59 + getComponentName(owner.type) || 'A component',
60 + );
61 + }
62
63 owner.stateNode._warnedAboutRefsInRender = true;
64 }
@@ -95,15 +96,16 @@ function findNodeHandle(componentOrHandle: any): ?number {
96 if (__DEV__) {
97 const owner = ReactCurrentOwner.current;
98 if (owner !== null && owner.stateNode !== null) {
98 - warningWithoutStack(
99 - owner.stateNode._warnedAboutRefsInRender,
100 - '%s is accessing findNodeHandle inside its render(). ' +
101 - 'render() should be a pure function of props and state. It should ' +
102 - 'never access something that requires stale data from the previous ' +
103 - 'render, such as refs. Move this logic to componentDidMount and ' +
104 - 'componentDidUpdate instead.',
105 - getComponentName(owner.type) || 'A component',
106 - );
99 + if (!owner.stateNode._warnedAboutRefsInRender) {
100 + warningWithoutStack(
101 + '%s is accessing findNodeHandle inside its render(). ' +
102 + 'render() should be a pure function of props and state. It should ' +
103 + 'never access something that requires stale data from the previous ' +
104 + 'render, such as refs. Move this logic to componentDidMount and ' +
105 + 'componentDidUpdate instead.',
106 + getComponentName(owner.type) || 'A component',
107 + );
108 + }
109
110 owner.stateNode._warnedAboutRefsInRender = true;
111 }
@@ -166,11 +168,12 @@ const ReactFabric: ReactFabricType = {
168
169 if (invalid) {
170 if (__DEV__) {
169 - warningWithoutStack(
170 - !invalid,
171 - "dispatchCommand was called with a ref that isn't a " +
172 - 'native component. Use React.forwardRef to get access to the underlying native component',
173 - );
171 + if (invalid) {
172 + warningWithoutStack(
173 + "dispatchCommand was called with a ref that isn't a " +
174 + 'native component. Use React.forwardRef to get access to the underlying native component',
175 + );
176 + }
177 }
178 return;
179 }
packages/react-native-renderer/src/ReactFabricEventResponderSystem.js
-1
@@ -180,7 +180,6 @@ function validateEventValue(eventValue: any): void {
180 const showWarning = name => {
181 if (__DEV__) {
182 warning(
183 - false,
183 '%s is not available on event objects created from event responder modules (React Flare). ' +
184 'Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.%s }`',
185 name,
packages/react-native-renderer/src/ReactFabricHostConfig.js
-2
@@ -161,7 +161,6 @@ class ReactFabricHostComponent {
161 ) {
162 if (__DEV__) {
163 warningWithoutStack(
164 - false,
164 'Warning: ref.measureLayout must be called with a ref to a native component.',
165 );
166 }
@@ -180,7 +179,6 @@ class ReactFabricHostComponent {
179 setNativeProps(nativeProps: Object) {
180 if (__DEV__) {
181 warningWithoutStack(
183 - false,
182 'Warning: setNativeProps is not currently supported in Fabric',
183 );
184 }
packages/react-native-renderer/src/ReactNativeComponent.js
-3
@@ -192,7 +192,6 @@ export default function(
192 if (maybeInstance.canonical) {
193 if (__DEV__) {
194 warningWithoutStack(
195 - false,
195 'Warning: measureLayout on components using NativeMethodsMixin ' +
196 'or ReactNative.NativeComponent is not currently supported in Fabric. ' +
197 'measureLayout must be called on a native ref. Consider using forwardRef.',
@@ -212,7 +211,6 @@ export default function(
211 if (relativeNode == null) {
212 if (__DEV__) {
213 warningWithoutStack(
215 - false,
214 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.',
215 );
216 }
@@ -260,7 +258,6 @@ export default function(
258 if (maybeInstance.canonical) {
259 if (__DEV__) {
260 warningWithoutStack(
263 - false,
261 'Warning: setNativeProps is not currently supported in Fabric',
262 );
263 }
packages/react-native-renderer/src/ReactNativeEventEmitter.js
-1
@@ -185,7 +185,6 @@ export function receiveTouches(
185 if (target < 1) {
186 if (__DEV__) {
187 warningWithoutStack(
188 - false,
188 'A view is reporting that a touch occurred on tag zero.',
189 );
190 }
packages/react-native-renderer/src/ReactNativeFiberHostComponent.js
-1
@@ -87,7 +87,6 @@ class ReactNativeFiberHostComponent {
87 if (relativeNode == null) {
88 if (__DEV__) {
89 warningWithoutStack(
90 - false,
90 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.',
91 );
92 }
packages/react-native-renderer/src/ReactNativeRenderer.js
+26 -23
@@ -53,15 +53,16 @@ function findHostInstance_DEPRECATED(
53 if (__DEV__) {
54 const owner = ReactCurrentOwner.current;
55 if (owner !== null && owner.stateNode !== null) {
56 - warningWithoutStack(
57 - owner.stateNode._warnedAboutRefsInRender,
58 - '%s is accessing findNodeHandle inside its render(). ' +
59 - 'render() should be a pure function of props and state. It should ' +
60 - 'never access something that requires stale data from the previous ' +
61 - 'render, such as refs. Move this logic to componentDidMount and ' +
62 - 'componentDidUpdate instead.',
63 - getComponentName(owner.type) || 'A component',
64 - );
56 + if (!owner.stateNode._warnedAboutRefsInRender) {
57 + warningWithoutStack(
58 + '%s is accessing findNodeHandle inside its render(). ' +
59 + 'render() should be a pure function of props and state. It should ' +
60 + 'never access something that requires stale data from the previous ' +
61 + 'render, such as refs. Move this logic to componentDidMount and ' +
62 + 'componentDidUpdate instead.',
63 + getComponentName(owner.type) || 'A component',
64 + );
65 + }
66
67 owner.stateNode._warnedAboutRefsInRender = true;
68 }
@@ -99,15 +100,16 @@ function findNodeHandle(componentOrHandle: any): ?number {
100 if (__DEV__) {
101 const owner = ReactCurrentOwner.current;
102 if (owner !== null && owner.stateNode !== null) {
102 - warningWithoutStack(
103 - owner.stateNode._warnedAboutRefsInRender,
104 - '%s is accessing findNodeHandle inside its render(). ' +
105 - 'render() should be a pure function of props and state. It should ' +
106 - 'never access something that requires stale data from the previous ' +
107 - 'render, such as refs. Move this logic to componentDidMount and ' +
108 - 'componentDidUpdate instead.',
109 - getComponentName(owner.type) || 'A component',
110 - );
103 + if (!owner.stateNode._warnedAboutRefsInRender) {
104 + warningWithoutStack(
105 + '%s is accessing findNodeHandle inside its render(). ' +
106 + 'render() should be a pure function of props and state. It should ' +
107 + 'never access something that requires stale data from the previous ' +
108 + 'render, such as refs. Move this logic to componentDidMount and ' +
109 + 'componentDidUpdate instead.',
110 + getComponentName(owner.type) || 'A component',
111 + );
112 + }
113
114 owner.stateNode._warnedAboutRefsInRender = true;
115 }
@@ -173,11 +175,12 @@ const ReactNativeRenderer: ReactNativeType = {
175 dispatchCommand(handle: any, command: string, args: Array<any>) {
176 if (handle._nativeTag == null) {
177 if (__DEV__) {
176 - warningWithoutStack(
177 - handle._nativeTag != null,
178 - "dispatchCommand was called with a ref that isn't a " +
179 - 'native component. Use React.forwardRef to get access to the underlying native component',
180 - );
178 + if (handle._nativeTag == null) {
179 + warningWithoutStack(
180 + "dispatchCommand was called with a ref that isn't a " +
181 + 'native component. Use React.forwardRef to get access to the underlying native component',
182 + );
183 + }
184 }
185 return;
186 }
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -/* eslint-disable react-internal/warning-and-invariant-args */
8 +/* eslint-disable react-internal/invariant-args */
9
10 'use strict';
11
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativeViewConfigRegistry.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow strict-local
8 */
9
10 -/* eslint-disable react-internal/warning-and-invariant-args */
10 +/* eslint-disable react-internal/invariant-args */
11
12 'use strict';
13
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/UIManager.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -/* eslint-disable react-internal/warning-and-invariant-args */
8 +/* eslint-disable react-internal/invariant-args */
9
10 'use strict';
11
packages/react-noop-renderer/src/createReactNoop.js
+7 -9
@@ -662,7 +662,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
662 if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
663 // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
664 warningWithoutStack(
665 - null,
665 'You seem to have overlapping act() calls, this is not supported. ' +
666 'Be sure to await previous act() calls before making a new one. ',
667 );
@@ -695,7 +694,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
694 .then(() => {
695 if (called === false) {
696 warningWithoutStack(
698 - null,
697 'You called act(async () => ...) without await. ' +
698 'This could lead to unexpected testing behaviour, interleaving multiple act ' +
699 'calls and mixing their scopes. You should - await act(async () => ...);',
@@ -742,12 +740,13 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
740 };
741 } else {
742 if (__DEV__) {
745 - warningWithoutStack(
746 - result === undefined,
747 - 'The callback passed to act(...) function ' +
748 - 'must return undefined, or a Promise. You returned %s',
749 - result,
750 - );
743 + if (result !== undefined) {
744 + warningWithoutStack(
745 + 'The callback passed to act(...) function ' +
746 + 'must return undefined, or a Promise. You returned %s',
747 + result,
748 + );
749 + }
750 }
751
752 // flush effects until none remain, and cleanup
@@ -772,7 +771,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
771 then(resolve: () => void) {
772 if (__DEV__) {
773 warningWithoutStack(
775 - false,
774 'Do not await the result of calling act(...) with sync logic, it is not a Promise.',
775 );
776 }
packages/react-reconciler/src/ReactChildFiber.js
+16 -19
@@ -93,7 +93,6 @@ if (__DEV__) {
93 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
94
95 warning(
96 - false,
96 'Each child in a list should have a unique ' +
97 '"key" prop. See https://fb.me/react-warning-keys for ' +
98 'more information.',
@@ -122,7 +121,6 @@ function coerceRef(
121 if (!didWarnAboutStringRefs[componentName]) {
122 if (warnAboutStringRefs) {
123 warningWithoutStack(
125 - false,
124 'Component "%s" contains the string ref "%s". Support for string refs ' +
125 'will be removed in a future major release. We recommend using ' +
126 'useRef() or createRef() instead. ' +
@@ -134,7 +132,6 @@ function coerceRef(
132 );
133 } else {
134 warningWithoutStack(
137 - false,
135 'A string ref, "%s", has been found within a strict mode tree. ' +
136 'String refs are a source of potential bugs and should be avoided. ' +
137 'We recommend using useRef() or createRef() instead. ' +
@@ -245,7 +242,6 @@ function warnOnFunctionType() {
242 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
243
244 warning(
248 - false,
245 'Functions are not valid as a React child. This may happen if ' +
246 'you return a Component instead of <Component /> from render. ' +
247 'Or maybe you meant to call this function rather than return it.',
@@ -739,7 +735,6 @@ function ChildReconciler(shouldTrackSideEffects) {
735 break;
736 }
737 warning(
742 - false,
738 'Encountered two children with the same key, `%s`. ' +
739 'Keys should be unique so that components maintain their identity ' +
740 'across updates. Non-unique keys may cause children to be ' +
@@ -938,25 +933,27 @@ function ChildReconciler(shouldTrackSideEffects) {
933 // $FlowFixMe Flow doesn't know about toStringTag
934 newChildrenIterable[Symbol.toStringTag] === 'Generator'
935 ) {
941 - warning(
942 - didWarnAboutGenerators,
943 - 'Using Generators as children is unsupported and will likely yield ' +
944 - 'unexpected results because enumerating a generator mutates it. ' +
945 - 'You may convert it to an array with `Array.from()` or the ' +
946 - '`[...spread]` operator before rendering. Keep in mind ' +
947 - 'you might need to polyfill these features for older browsers.',
948 - );
936 + if (!didWarnAboutGenerators) {
937 + warning(
938 + 'Using Generators as children is unsupported and will likely yield ' +
939 + 'unexpected results because enumerating a generator mutates it. ' +
940 + 'You may convert it to an array with `Array.from()` or the ' +
941 + '`[...spread]` operator before rendering. Keep in mind ' +
942 + 'you might need to polyfill these features for older browsers.',
943 + );
944 + }
945 didWarnAboutGenerators = true;
946 }
947
948 // Warn about using Maps as children
949 if ((newChildrenIterable: any).entries === iteratorFn) {
954 - warning(
955 - didWarnAboutMaps,
956 - 'Using Maps as children is unsupported and will likely yield ' +
957 - 'unexpected results. Convert it to a sequence/iterable of keyed ' +
958 - 'ReactElements instead.',
959 - );
950 + if (!didWarnAboutMaps) {
951 + warning(
952 + 'Using Maps as children is unsupported and will likely yield ' +
953 + 'unexpected results. Convert it to a sequence/iterable of keyed ' +
954 + 'ReactElements instead.',
955 + );
956 + }
957 didWarnAboutMaps = true;
958 }
959
packages/react-reconciler/src/ReactFiber.js
-1
@@ -806,7 +806,6 @@ function createFiberFromProfiler(
806 typeof pendingProps.onRender !== 'function'
807 ) {
808 warningWithoutStack(
809 - false,
809 'Profiler must specify an "id" string and "onRender" function as props',
810 );
811 }
packages/react-reconciler/src/ReactFiberBeginWork.js
+21 -36
@@ -782,12 +782,13 @@ function updateClassComponent(
782 if (__DEV__) {
783 let inst = workInProgress.stateNode;
784 if (inst.props !== nextProps) {
785 - warning(
786 - didWarnAboutReassigningProps,
787 - 'It looks like %s is reassigning its own `this.props` while rendering. ' +
788 - 'This is not supported and can lead to confusing bugs.',
789 - getComponentName(workInProgress.type) || 'a component',
790 - );
785 + if (!didWarnAboutReassigningProps) {
786 + warning(
787 + 'It looks like %s is reassigning its own `this.props` while rendering. ' +
788 + 'This is not supported and can lead to confusing bugs.',
789 + getComponentName(workInProgress.type) || 'a component',
790 + );
791 + }
792 didWarnAboutReassigningProps = true;
793 }
794 }
@@ -1257,7 +1258,6 @@ function mountIndeterminateComponent(
1258
1259 if (!didWarnAboutBadClass[componentName]) {
1260 warningWithoutStack(
1260 - false,
1261 "The <%s /> component appears to have a render method, but doesn't extend React.Component. " +
1262 'This is likely to cause errors. Change %s to extend React.Component instead.',
1263 componentName,
@@ -1303,7 +1303,6 @@ function mountIndeterminateComponent(
1303 const componentName = getComponentName(Component) || 'Unknown';
1304 if (!didWarnAboutModulePatternComponent[componentName]) {
1305 warningWithoutStack(
1306 - false,
1306 'The <%s /> component appears to be a function component that returns a class instance. ' +
1307 'Change %s to a class that extends React.Component instead. ' +
1308 "If you can't use a class try assigning the prototype on the function as a workaround. " +
@@ -1365,7 +1364,6 @@ function mountIndeterminateComponent(
1364 if (__DEV__) {
1365 if (disableLegacyContext && Component.contextTypes) {
1366 warningWithoutStack(
1368 - false,
1367 '%s uses the legacy contextTypes API which is no longer supported. ' +
1368 'Use React.createContext() with React.useContext() instead.',
1369 getComponentName(Component) || 'Unknown',
@@ -1400,11 +1398,12 @@ function mountIndeterminateComponent(
1398 function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
1399 if (__DEV__) {
1400 if (Component) {
1403 - warningWithoutStack(
1404 - !Component.childContextTypes,
1405 - '%s(...): childContextTypes cannot be defined on a function component.',
1406 - Component.displayName || Component.name || 'Component',
1407 - );
1401 + if (Component.childContextTypes) {
1402 + warningWithoutStack(
1403 + '%s(...): childContextTypes cannot be defined on a function component.',
1404 + Component.displayName || Component.name || 'Component',
1405 + );
1406 + }
1407 }
1408 if (workInProgress.ref !== null) {
1409 let info = '';
@@ -1421,7 +1420,6 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
1420 if (!didWarnAboutFunctionRefs[warningKey]) {
1421 didWarnAboutFunctionRefs[warningKey] = true;
1422 warning(
1424 - false,
1423 'Function components cannot be given refs. ' +
1424 'Attempts to access this ref will fail. ' +
1425 'Did you mean to use React.forwardRef()?%s',
@@ -1438,7 +1436,6 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
1436
1437 if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
1438 warningWithoutStack(
1441 - false,
1439 '%s: Support for defaultProps will be removed from function components ' +
1440 'in a future major release. Use JavaScript default parameters instead.',
1441 componentName,
@@ -1452,7 +1449,6 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
1449
1450 if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) {
1451 warningWithoutStack(
1455 - false,
1452 '%s: Function components do not support getDerivedStateFromProps.',
1453 componentName,
1454 );
@@ -1468,7 +1464,6 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
1464
1465 if (!didWarnAboutContextTypeOnFunctionComponent[componentName]) {
1466 warningWithoutStack(
1471 - false,
1467 '%s: Function components do not support contextType.',
1468 componentName,
1469 );
@@ -1559,7 +1554,6 @@ function updateSuspenseComponent(
1554 if (!didWarnAboutMaxDuration) {
1555 didWarnAboutMaxDuration = true;
1556 warning(
1562 - false,
1557 'maxDuration has been removed from React. ' +
1558 'Remove the maxDuration prop.',
1559 );
@@ -1967,7 +1961,6 @@ function mountDehydratedSuspenseComponent(
1961 if ((workInProgress.mode & BlockingMode) === NoMode) {
1962 if (__DEV__) {
1963 warning(
1970 - false,
1964 'Cannot hydrate Suspense in legacy mode. Switch from ' +
1965 'ReactDOM.hydrate(element, container) to ' +
1966 'ReactDOM.createBlockingRoot(container, { hydrate: true })' +
@@ -2213,7 +2206,6 @@ function validateRevealOrder(revealOrder: SuspenseListRevealOrder) {
2206 case 'forwards':
2207 case 'backwards': {
2208 warning(
2216 - false,
2209 '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
2210 'Use lowercase "%s" instead.',
2211 revealOrder,
@@ -2224,7 +2216,6 @@ function validateRevealOrder(revealOrder: SuspenseListRevealOrder) {
2216 case 'forward':
2217 case 'backward': {
2218 warning(
2227 - false,
2219 '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
2220 'React uses the -s suffix in the spelling. Use "%ss" instead.',
2221 revealOrder,
@@ -2234,7 +2225,6 @@ function validateRevealOrder(revealOrder: SuspenseListRevealOrder) {
2225 }
2226 default:
2227 warning(
2237 - false,
2228 '"%s" is not a supported revealOrder on <SuspenseList />. ' +
2229 'Did you mean "together", "forwards" or "backwards"?',
2230 revealOrder,
@@ -2243,7 +2233,6 @@ function validateRevealOrder(revealOrder: SuspenseListRevealOrder) {
2233 }
2234 } else {
2235 warning(
2246 - false,
2236 '%s is not a supported value for revealOrder on <SuspenseList />. ' +
2237 'Did you mean "together", "forwards" or "backwards"?',
2238 revealOrder,
@@ -2262,7 +2251,6 @@ function validateTailOptions(
2251 if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
2252 didWarnAboutTailOptions[tailMode] = true;
2253 warning(
2265 - false,
2254 '"%s" is not a supported value for tail on <SuspenseList />. ' +
2255 'Did you mean "collapsed" or "hidden"?',
2256 tailMode,
@@ -2270,7 +2258,6 @@ function validateTailOptions(
2258 } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
2259 didWarnAboutTailOptions[tailMode] = true;
2260 warning(
2273 - false,
2261 '<SuspenseList tail="%s" /> is only valid if revealOrder is ' +
2262 '"forwards" or "backwards". ' +
2263 'Did you mean to specify revealOrder="forwards"?',
@@ -2288,7 +2275,6 @@ function validateSuspenseListNestedChild(childSlot: mixed, index: number) {
2275 if (isArray || isIterable) {
2276 let type = isArray ? 'array' : 'iterable';
2277 warning(
2291 - false,
2278 'A nested %s was passed to row #%s in <SuspenseList />. Wrap it in ' +
2279 'an additional SuspenseList to configure its revealOrder: ' +
2280 '<SuspenseList revealOrder=...> ... ' +
@@ -2335,7 +2321,6 @@ function validateSuspenseListChildren(
2321 }
2322 } else {
2323 warning(
2338 - false,
2324 'A single row was passed to a <SuspenseList revealOrder="%s" />. ' +
2325 'This is not useful since it needs multiple rows. ' +
2326 'Did you mean to pass multiple children or an array?',
@@ -2631,7 +2616,6 @@ function updateContextConsumer(
2616 if (!hasWarnedAboutUsingContextAsConsumer) {
2617 hasWarnedAboutUsingContextAsConsumer = true;
2618 warning(
2634 - false,
2619 'Rendering <Context> directly is not supported and will be removed in ' +
2620 'a future major release. Did you mean to render <Context.Consumer> instead?',
2621 );
@@ -2645,13 +2629,14 @@ function updateContextConsumer(
2629 const render = newProps.children;
2630
2631 if (__DEV__) {
2648 - warningWithoutStack(
2649 - typeof render === 'function',
2650 - 'A context consumer was rendered with multiple children, or a child ' +
2651 - "that isn't a function. A context consumer expects a single child " +
2652 - 'that is a function. If you did pass a function, make sure there ' +
2653 - 'is no trailing or leading whitespace around it.',
2654 - );
2632 + if (typeof render !== 'function') {
2633 + warningWithoutStack(
2634 + 'A context consumer was rendered with multiple children, or a child ' +
2635 + "that isn't a function. A context consumer expects a single child " +
2636 + 'that is a function. If you did pass a function, make sure there ' +
2637 + 'is no trailing or leading whitespace around it.',
2638 + );
2639 + }
2640 }
2641
2642 prepareToReadContext(workInProgress, renderExpirationTime);
packages/react-reconciler/src/ReactFiberClassComponent.js
+133 -154
@@ -96,7 +96,6 @@ if (__DEV__) {
96 if (!didWarnOnInvalidCallback.has(key)) {
97 didWarnOnInvalidCallback.add(key);
98 warningWithoutStack(
99 - false,
99 '%s(...): Expected the last optional `callback` argument to be a ' +
100 'function. Instead received: %s.',
101 callerName,
@@ -111,7 +110,6 @@ if (__DEV__) {
110 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
111 didWarnAboutUndefinedDerivedState.add(componentName);
112 warningWithoutStack(
114 - false,
113 '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' +
114 'You have returned undefined.',
115 componentName,
@@ -274,12 +272,13 @@ function checkShouldComponentUpdate(
272 stopPhaseTimer();
273
274 if (__DEV__) {
277 - warningWithoutStack(
278 - shouldUpdate !== undefined,
279 - '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
280 - 'boolean value. Make sure to return true or false.',
281 - getComponentName(ctor) || 'Component',
282 - );
275 + if (shouldUpdate === undefined) {
276 + warningWithoutStack(
277 + '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
278 + 'boolean value. Make sure to return true or false.',
279 + getComponentName(ctor) || 'Component',
280 + );
281 + }
282 }
283
284 return shouldUpdate;
@@ -303,14 +302,12 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
302 if (!renderPresent) {
303 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
304 warningWithoutStack(
306 - false,
305 '%s(...): No `render` method found on the returned component ' +
306 'instance: did you accidentally return an object from the constructor?',
307 name,
308 );
309 } else {
310 warningWithoutStack(
313 - false,
311 '%s(...): No `render` method found on the returned component ' +
312 'instance: you may have forgotten to define `render`.',
313 name,
@@ -318,46 +315,47 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
315 }
316 }
317
321 - const noGetInitialStateOnES6 =
322 - !instance.getInitialState ||
323 - instance.getInitialState.isReactClassApproved ||
324 - instance.state;
325 - warningWithoutStack(
326 - noGetInitialStateOnES6,
327 - 'getInitialState was defined on %s, a plain JavaScript class. ' +
328 - 'This is only supported for classes created using React.createClass. ' +
329 - 'Did you mean to define a state property instead?',
330 - name,
331 - );
332 - const noGetDefaultPropsOnES6 =
333 - !instance.getDefaultProps ||
334 - instance.getDefaultProps.isReactClassApproved;
335 - warningWithoutStack(
336 - noGetDefaultPropsOnES6,
337 - 'getDefaultProps was defined on %s, a plain JavaScript class. ' +
338 - 'This is only supported for classes created using React.createClass. ' +
339 - 'Use a static property to define defaultProps instead.',
340 - name,
341 - );
342 - const noInstancePropTypes = !instance.propTypes;
343 - warningWithoutStack(
344 - noInstancePropTypes,
345 - 'propTypes was defined as an instance property on %s. Use a static ' +
346 - 'property to define propTypes instead.',
347 - name,
348 - );
349 - const noInstanceContextType = !instance.contextType;
350 - warningWithoutStack(
351 - noInstanceContextType,
352 - 'contextType was defined as an instance property on %s. Use a static ' +
353 - 'property to define contextType instead.',
354 - name,
355 - );
318 + if (
319 + instance.getInitialState &&
320 + !instance.getInitialState.isReactClassApproved &&
321 + !instance.state
322 + ) {
323 + warningWithoutStack(
324 + 'getInitialState was defined on %s, a plain JavaScript class. ' +
325 + 'This is only supported for classes created using React.createClass. ' +
326 + 'Did you mean to define a state property instead?',
327 + name,
328 + );
329 + }
330 + if (
331 + instance.getDefaultProps &&
332 + !instance.getDefaultProps.isReactClassApproved
333 + ) {
334 + warningWithoutStack(
335 + 'getDefaultProps was defined on %s, a plain JavaScript class. ' +
336 + 'This is only supported for classes created using React.createClass. ' +
337 + 'Use a static property to define defaultProps instead.',
338 + name,
339 + );
340 + }
341 + if (instance.propTypes) {
342 + warningWithoutStack(
343 + 'propTypes was defined as an instance property on %s. Use a static ' +
344 + 'property to define propTypes instead.',
345 + name,
346 + );
347 + }
348 + if (instance.contextType) {
349 + warningWithoutStack(
350 + 'contextType was defined as an instance property on %s. Use a static ' +
351 + 'property to define contextType instead.',
352 + name,
353 + );
354 + }
355
356 if (disableLegacyContext) {
357 if (ctor.childContextTypes) {
358 warningWithoutStack(
360 - false,
359 '%s uses the legacy childContextTypes API which is no longer supported. ' +
360 'Use React.createContext() instead.',
361 name,
@@ -365,20 +363,19 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
363 }
364 if (ctor.contextTypes) {
365 warningWithoutStack(
368 - false,
366 '%s uses the legacy contextTypes API which is no longer supported. ' +
367 'Use React.createContext() with static contextType instead.',
368 name,
369 );
370 }
371 } else {
375 - const noInstanceContextTypes = !instance.contextTypes;
376 - warningWithoutStack(
377 - noInstanceContextTypes,
378 - 'contextTypes was defined as an instance property on %s. Use a static ' +
379 - 'property to define contextTypes instead.',
380 - name,
381 - );
372 + if (instance.contextTypes) {
373 + warningWithoutStack(
374 + 'contextTypes was defined as an instance property on %s. Use a static ' +
375 + 'property to define contextTypes instead.',
376 + name,
377 + );
378 + }
379
380 if (
381 ctor.contextType &&
@@ -387,7 +384,6 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
384 ) {
385 didWarnAboutContextTypeAndContextTypes.add(ctor);
386 warningWithoutStack(
390 - false,
387 '%s declares both contextTypes and contextType static properties. ' +
388 'The legacy contextTypes property will be ignored.',
389 name,
@@ -395,81 +391,76 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
391 }
392 }
393
398 - const noComponentShouldUpdate =
399 - typeof instance.componentShouldUpdate !== 'function';
400 - warningWithoutStack(
401 - noComponentShouldUpdate,
402 - '%s has a method called ' +
403 - 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
404 - 'The name is phrased as a question because the function is ' +
405 - 'expected to return a value.',
406 - name,
407 - );
394 + if (typeof instance.componentShouldUpdate === 'function') {
395 + warningWithoutStack(
396 + '%s has a method called ' +
397 + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
398 + 'The name is phrased as a question because the function is ' +
399 + 'expected to return a value.',
400 + name,
401 + );
402 + }
403 if (
404 ctor.prototype &&
405 ctor.prototype.isPureReactComponent &&
406 typeof instance.shouldComponentUpdate !== 'undefined'
407 ) {
408 warningWithoutStack(
414 - false,
409 '%s has a method called shouldComponentUpdate(). ' +
410 'shouldComponentUpdate should not be used when extending React.PureComponent. ' +
411 'Please extend React.Component if shouldComponentUpdate is used.',
412 getComponentName(ctor) || 'A pure component',
413 );
414 }
421 - const noComponentDidUnmount =
422 - typeof instance.componentDidUnmount !== 'function';
423 - warningWithoutStack(
424 - noComponentDidUnmount,
425 - '%s has a method called ' +
426 - 'componentDidUnmount(). But there is no such lifecycle method. ' +
427 - 'Did you mean componentWillUnmount()?',
428 - name,
429 - );
430 - const noComponentDidReceiveProps =
431 - typeof instance.componentDidReceiveProps !== 'function';
432 - warningWithoutStack(
433 - noComponentDidReceiveProps,
434 - '%s has a method called ' +
435 - 'componentDidReceiveProps(). But there is no such lifecycle method. ' +
436 - 'If you meant to update the state in response to changing props, ' +
437 - 'use componentWillReceiveProps(). If you meant to fetch data or ' +
438 - 'run side-effects or mutations after React has updated the UI, use componentDidUpdate().',
439 - name,
440 - );
441 - const noComponentWillRecieveProps =
442 - typeof instance.componentWillRecieveProps !== 'function';
443 - warningWithoutStack(
444 - noComponentWillRecieveProps,
445 - '%s has a method called ' +
446 - 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
447 - name,
448 - );
449 - const noUnsafeComponentWillRecieveProps =
450 - typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
451 - warningWithoutStack(
452 - noUnsafeComponentWillRecieveProps,
453 - '%s has a method called ' +
454 - 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?',
455 - name,
456 - );
415 + if (typeof instance.componentDidUnmount === 'function') {
416 + warningWithoutStack(
417 + '%s has a method called ' +
418 + 'componentDidUnmount(). But there is no such lifecycle method. ' +
419 + 'Did you mean componentWillUnmount()?',
420 + name,
421 + );
422 + }
423 + if (typeof instance.componentDidReceiveProps === 'function') {
424 + warningWithoutStack(
425 + '%s has a method called ' +
426 + 'componentDidReceiveProps(). But there is no such lifecycle method. ' +
427 + 'If you meant to update the state in response to changing props, ' +
428 + 'use componentWillReceiveProps(). If you meant to fetch data or ' +
429 + 'run side-effects or mutations after React has updated the UI, use componentDidUpdate().',
430 + name,
431 + );
432 + }
433 + if (typeof instance.componentWillRecieveProps === 'function') {
434 + warningWithoutStack(
435 + '%s has a method called ' +
436 + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
437 + name,
438 + );
439 + }
440 + if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
441 + warningWithoutStack(
442 + '%s has a method called ' +
443 + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?',
444 + name,
445 + );
446 + }
447 const hasMutatedProps = instance.props !== newProps;
458 - warningWithoutStack(
459 - instance.props === undefined || !hasMutatedProps,
460 - '%s(...): When calling super() in `%s`, make sure to pass ' +
461 - "up the same props that your component's constructor was passed.",
462 - name,
463 - name,
464 - );
465 - const noInstanceDefaultProps = !instance.defaultProps;
466 - warningWithoutStack(
467 - noInstanceDefaultProps,
468 - 'Setting defaultProps as an instance property on %s is not supported and will be ignored.' +
469 - ' Instead, define defaultProps as a static property on %s.',
470 - name,
471 - name,
472 - );
448 + if (instance.props !== undefined && hasMutatedProps) {
449 + warningWithoutStack(
450 + '%s(...): When calling super() in `%s`, make sure to pass ' +
451 + "up the same props that your component's constructor was passed.",
452 + name,
453 + name,
454 + );
455 + }
456 + if (instance.defaultProps) {
457 + warningWithoutStack(
458 + 'Setting defaultProps as an instance property on %s is not supported and will be ignored.' +
459 + ' Instead, define defaultProps as a static property on %s.',
460 + name,
461 + name,
462 + );
463 + }
464
465 if (
466 typeof instance.getSnapshotBeforeUpdate === 'function' &&
@@ -478,48 +469,42 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
469 ) {
470 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
471 warningWithoutStack(
481 - false,
472 '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' +
473 'This component defines getSnapshotBeforeUpdate() only.',
474 getComponentName(ctor),
475 );
476 }
477
488 - const noInstanceGetDerivedStateFromProps =
489 - typeof instance.getDerivedStateFromProps !== 'function';
490 - warningWithoutStack(
491 - noInstanceGetDerivedStateFromProps,
492 - '%s: getDerivedStateFromProps() is defined as an instance method ' +
493 - 'and will be ignored. Instead, declare it as a static method.',
494 - name,
495 - );
496 - const noInstanceGetDerivedStateFromCatch =
497 - typeof instance.getDerivedStateFromError !== 'function';
498 - warningWithoutStack(
499 - noInstanceGetDerivedStateFromCatch,
500 - '%s: getDerivedStateFromError() is defined as an instance method ' +
501 - 'and will be ignored. Instead, declare it as a static method.',
502 - name,
503 - );
504 - const noStaticGetSnapshotBeforeUpdate =
505 - typeof ctor.getSnapshotBeforeUpdate !== 'function';
506 - warningWithoutStack(
507 - noStaticGetSnapshotBeforeUpdate,
508 - '%s: getSnapshotBeforeUpdate() is defined as a static method ' +
509 - 'and will be ignored. Instead, declare it as an instance method.',
510 - name,
511 - );
512 - const state = instance.state;
513 - if (state && (typeof state !== 'object' || isArray(state))) {
478 + if (typeof instance.getDerivedStateFromProps === 'function') {
479 warningWithoutStack(
515 - false,
516 - '%s.state: must be set to an object or null',
480 + '%s: getDerivedStateFromProps() is defined as an instance method ' +
481 + 'and will be ignored. Instead, declare it as a static method.',
482 + name,
483 + );
484 + }
485 + if (typeof instance.getDerivedStateFromError === 'function') {
486 + warningWithoutStack(
487 + '%s: getDerivedStateFromError() is defined as an instance method ' +
488 + 'and will be ignored. Instead, declare it as a static method.',
489 + name,
490 + );
491 + }
492 + if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
493 + warningWithoutStack(
494 + '%s: getSnapshotBeforeUpdate() is defined as a static method ' +
495 + 'and will be ignored. Instead, declare it as an instance method.',
496 name,
497 );
498 }
520 - if (typeof instance.getChildContext === 'function') {
499 + const state = instance.state;
500 + if (state && (typeof state !== 'object' || isArray(state))) {
501 + warningWithoutStack('%s.state: must be set to an object or null', name);
502 + }
503 + if (
504 + typeof instance.getChildContext === 'function' &&
505 + typeof ctor.childContextTypes !== 'object'
506 + ) {
507 warningWithoutStack(
522 - typeof ctor.childContextTypes === 'object',
508 '%s.getChildContext(): childContextTypes must be defined in order to ' +
509 'use getChildContext().',
510 name,
@@ -582,7 +567,6 @@ function constructClassInstance(
567 '}.';
568 }
569 warningWithoutStack(
585 - false,
570 '%s defines an invalid contextType. ' +
571 'contextType should point to the Context object returned by React.createContext().%s',
572 getComponentName(ctor) || 'Component',
@@ -627,7 +611,6 @@ function constructClassInstance(
611 if (!didWarnAboutUninitializedState.has(componentName)) {
612 didWarnAboutUninitializedState.add(componentName);
613 warningWithoutStack(
630 - false,
614 '`%s` uses `getDerivedStateFromProps` but its initial state is ' +
615 '%s. This is not recommended. Instead, define the initial state by ' +
616 'assigning an object to `this.state` in the constructor of `%s`. ' +
@@ -688,7 +671,6 @@ function constructClassInstance(
671 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(componentName)) {
672 didWarnAboutLegacyLifecyclesAndDerivedState.add(componentName);
673 warningWithoutStack(
691 - false,
674 'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
675 '%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n' +
676 'The above lifecycles should be removed. Learn more about this warning here:\n' +
@@ -731,7 +713,6 @@ function callComponentWillMount(workInProgress, instance) {
713 if (oldState !== instance.state) {
714 if (__DEV__) {
715 warningWithoutStack(
734 - false,
716 '%s.componentWillMount(): Assigning directly to this.state is ' +
717 "deprecated (except inside a component's " +
718 'constructor). Use setState instead.',
@@ -765,7 +746,6 @@ function callComponentWillReceiveProps(
746 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
747 didWarnAboutStateAssignmentForComponent.add(componentName);
748 warningWithoutStack(
768 - false,
749 '%s.componentWillReceiveProps(): Assigning directly to ' +
750 "this.state is deprecated (except inside a component's " +
751 'constructor). Use setState instead.',
@@ -811,7 +791,6 @@ function mountClassInstance(
791 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
792 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
793 warningWithoutStack(
814 - false,
794 '%s: It is not recommended to assign props directly to state ' +
795 "because updates to props won't be reflected in state. " +
796 'In most cases, it is better to use props directly.',
packages/react-reconciler/src/ReactFiberCommitWork.js
+81 -76
@@ -268,24 +268,26 @@ function commitBeforeMutationLifeCycles(
268 finishedWork.type === finishedWork.elementType &&
269 !didWarnAboutReassigningProps
270 ) {
271 - warning(
272 - instance.props === finishedWork.memoizedProps,
273 - 'Expected %s props to match memoized props before ' +
274 - 'getSnapshotBeforeUpdate. ' +
275 - 'This might either be because of a bug in React, or because ' +
276 - 'a component reassigns its own `this.props`. ' +
277 - 'Please file an issue.',
278 - getComponentName(finishedWork.type) || 'instance',
279 - );
280 - warning(
281 - instance.state === finishedWork.memoizedState,
282 - 'Expected %s state to match memoized state before ' +
283 - 'getSnapshotBeforeUpdate. ' +
284 - 'This might either be because of a bug in React, or because ' +
285 - 'a component reassigns its own `this.props`. ' +
286 - 'Please file an issue.',
287 - getComponentName(finishedWork.type) || 'instance',
288 - );
271 + if (instance.props !== finishedWork.memoizedProps) {
272 + warning(
273 + 'Expected %s props to match memoized props before ' +
274 + 'getSnapshotBeforeUpdate. ' +
275 + 'This might either be because of a bug in React, or because ' +
276 + 'a component reassigns its own `this.props`. ' +
277 + 'Please file an issue.',
278 + getComponentName(finishedWork.type) || 'instance',
279 + );
280 + }
281 + if (instance.state !== finishedWork.memoizedState) {
282 + warning(
283 + 'Expected %s state to match memoized state before ' +
284 + 'getSnapshotBeforeUpdate. ' +
285 + 'This might either be because of a bug in React, or because ' +
286 + 'a component reassigns its own `this.props`. ' +
287 + 'Please file an issue.',
288 + getComponentName(finishedWork.type) || 'instance',
289 + );
290 + }
291 }
292 }
293 const snapshot = instance.getSnapshotBeforeUpdate(
@@ -301,7 +303,6 @@ function commitBeforeMutationLifeCycles(
303 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
304 didWarnSet.add(finishedWork.type);
305 warningWithoutStack(
304 - false,
306 '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +
307 'must be returned. You have returned undefined.',
308 getComponentName(finishedWork.type),
@@ -381,7 +382,6 @@ function commitHookEffectList(
382 addendum = ' You returned: ' + destroy;
383 }
384 warningWithoutStack(
384 - false,
385 'An effect function must not return anything besides a function, ' +
386 'which is used for clean-up.%s%s',
387 addendum,
@@ -437,24 +437,26 @@ function commitLifeCycles(
437 finishedWork.type === finishedWork.elementType &&
438 !didWarnAboutReassigningProps
439 ) {
440 - warning(
441 - instance.props === finishedWork.memoizedProps,
442 - 'Expected %s props to match memoized props before ' +
443 - 'componentDidMount. ' +
444 - 'This might either be because of a bug in React, or because ' +
445 - 'a component reassigns its own `this.props`. ' +
446 - 'Please file an issue.',
447 - getComponentName(finishedWork.type) || 'instance',
448 - );
449 - warning(
450 - instance.state === finishedWork.memoizedState,
451 - 'Expected %s state to match memoized state before ' +
452 - 'componentDidMount. ' +
453 - 'This might either be because of a bug in React, or because ' +
454 - 'a component reassigns its own `this.props`. ' +
455 - 'Please file an issue.',
456 - getComponentName(finishedWork.type) || 'instance',
457 - );
440 + if (instance.props !== finishedWork.memoizedProps) {
441 + warning(
442 + 'Expected %s props to match memoized props before ' +
443 + 'componentDidMount. ' +
444 + 'This might either be because of a bug in React, or because ' +
445 + 'a component reassigns its own `this.props`. ' +
446 + 'Please file an issue.',
447 + getComponentName(finishedWork.type) || 'instance',
448 + );
449 + }
450 + if (instance.state !== finishedWork.memoizedState) {
451 + warning(
452 + 'Expected %s state to match memoized state before ' +
453 + 'componentDidMount. ' +
454 + 'This might either be because of a bug in React, or because ' +
455 + 'a component reassigns its own `this.props`. ' +
456 + 'Please file an issue.',
457 + getComponentName(finishedWork.type) || 'instance',
458 + );
459 + }
460 }
461 }
462 instance.componentDidMount();
@@ -474,24 +476,26 @@ function commitLifeCycles(
476 finishedWork.type === finishedWork.elementType &&
477 !didWarnAboutReassigningProps
478 ) {
477 - warning(
478 - instance.props === finishedWork.memoizedProps,
479 - 'Expected %s props to match memoized props before ' +
480 - 'componentDidUpdate. ' +
481 - 'This might either be because of a bug in React, or because ' +
482 - 'a component reassigns its own `this.props`. ' +
483 - 'Please file an issue.',
484 - getComponentName(finishedWork.type) || 'instance',
485 - );
486 - warning(
487 - instance.state === finishedWork.memoizedState,
488 - 'Expected %s state to match memoized state before ' +
489 - 'componentDidUpdate. ' +
490 - 'This might either be because of a bug in React, or because ' +
491 - 'a component reassigns its own `this.props`. ' +
492 - 'Please file an issue.',
493 - getComponentName(finishedWork.type) || 'instance',
494 - );
479 + if (instance.props !== finishedWork.memoizedProps) {
480 + warning(
481 + 'Expected %s props to match memoized props before ' +
482 + 'componentDidUpdate. ' +
483 + 'This might either be because of a bug in React, or because ' +
484 + 'a component reassigns its own `this.props`. ' +
485 + 'Please file an issue.',
486 + getComponentName(finishedWork.type) || 'instance',
487 + );
488 + }
489 + if (instance.state !== finishedWork.memoizedState) {
490 + warning(
491 + 'Expected %s state to match memoized state before ' +
492 + 'componentDidUpdate. ' +
493 + 'This might either be because of a bug in React, or because ' +
494 + 'a component reassigns its own `this.props`. ' +
495 + 'Please file an issue.',
496 + getComponentName(finishedWork.type) || 'instance',
497 + );
498 + }
499 }
500 }
501 instance.componentDidUpdate(
@@ -509,24 +513,26 @@ function commitLifeCycles(
513 finishedWork.type === finishedWork.elementType &&
514 !didWarnAboutReassigningProps
515 ) {
512 - warning(
513 - instance.props === finishedWork.memoizedProps,
514 - 'Expected %s props to match memoized props before ' +
515 - 'processing the update queue. ' +
516 - 'This might either be because of a bug in React, or because ' +
517 - 'a component reassigns its own `this.props`. ' +
518 - 'Please file an issue.',
519 - getComponentName(finishedWork.type) || 'instance',
520 - );
521 - warning(
522 - instance.state === finishedWork.memoizedState,
523 - 'Expected %s state to match memoized state before ' +
524 - 'processing the update queue. ' +
525 - 'This might either be because of a bug in React, or because ' +
526 - 'a component reassigns its own `this.props`. ' +
527 - 'Please file an issue.',
528 - getComponentName(finishedWork.type) || 'instance',
529 - );
516 + if (instance.props !== finishedWork.memoizedProps) {
517 + warning(
518 + 'Expected %s props to match memoized props before ' +
519 + 'processing the update queue. ' +
520 + 'This might either be because of a bug in React, or because ' +
521 + 'a component reassigns its own `this.props`. ' +
522 + 'Please file an issue.',
523 + getComponentName(finishedWork.type) || 'instance',
524 + );
525 + }
526 + if (instance.state !== finishedWork.memoizedState) {
527 + warning(
528 + 'Expected %s state to match memoized state before ' +
529 + 'processing the update queue. ' +
530 + 'This might either be because of a bug in React, or because ' +
531 + 'a component reassigns its own `this.props`. ' +
532 + 'Please file an issue.',
533 + getComponentName(finishedWork.type) || 'instance',
534 + );
535 + }
536 }
537 }
538 // We could update instance props and state here,
@@ -708,7 +714,6 @@ function commitAttachRef(finishedWork: Fiber) {
714 if (__DEV__) {
715 if (!ref.hasOwnProperty('current')) {
716 warningWithoutStack(
711 - false,
717 'Unexpected ref object provided for %s. ' +
718 'Use either a ref-setter function or React.createRef().%s',
719 getComponentName(finishedWork.type),
@@ -1460,7 +1465,7 @@ function commitSuspenseComponent(finishedWork: Fiber) {
1465 }
1466 } else if (__DEV__) {
1467 if (suspenseCallback !== undefined) {
1463 - warning(false, 'Unexpected type for suspenseCallback.');
1468 + warning('Unexpected type for suspenseCallback.');
1469 }
1470 }
1471 }
packages/react-reconciler/src/ReactFiberContext.js
-1
@@ -199,7 +199,6 @@ function processChildContext(
199 if (!warnedAboutMissingGetChildContext[componentName]) {
200 warnedAboutMissingGetChildContext[componentName] = true;
201 warningWithoutStack(
202 - false,
202 '%s.childContextTypes is specified but there is no getChildContext() method ' +
203 'on the instance. You can either define getChildContext() on %s or remove ' +
204 'childContextTypes from it.',
packages/react-reconciler/src/ReactFiberDevToolsHook.js
-5
@@ -44,7 +44,6 @@ export function injectInternals(internals: Object): boolean {
44 if (!hook.supportsFiber) {
45 if (__DEV__) {
46 warningWithoutStack(
47 - false,
47 'The installed version of React DevTools is too old and will not work ' +
48 'with the current version of React. Please update React DevTools. ' +
49 'https://fb.me/react-devtools',
@@ -66,7 +65,6 @@ export function injectInternals(internals: Object): boolean {
65 if (__DEV__ && !hasLoggedError) {
66 hasLoggedError = true;
67 warningWithoutStack(
69 - false,
68 'React instrumentation encountered an error: %s',
69 err,
70 );
@@ -93,7 +91,6 @@ export function injectInternals(internals: Object): boolean {
91 if (!hasLoggedError) {
92 hasLoggedError = true;
93 warningWithoutStack(
96 - false,
94 'React instrumentation encountered an error: %s',
95 err,
96 );
@@ -109,7 +106,6 @@ export function injectInternals(internals: Object): boolean {
106 if (!hasLoggedError) {
107 hasLoggedError = true;
108 warningWithoutStack(
112 - false,
109 'React instrumentation encountered an error: %s',
110 err,
111 );
@@ -121,7 +117,6 @@ export function injectInternals(internals: Object): boolean {
117 // Catch all errors because it is unsafe to throw during initialization.
118 if (__DEV__) {
119 warningWithoutStack(
124 - false,
120 'React instrumentation encountered an error: %s.',
121 err,
122 );
packages/react-reconciler/src/ReactFiberEvents.js
-1
@@ -119,7 +119,6 @@ function updateEventListener(
119 // show warning
120 if (__DEV__) {
121 warning(
122 - false,
122 'Duplicate event responder "%s" found in event listeners. ' +
123 'Event listeners passed to elements cannot use the same event responder more than once.',
124 responder.displayName,
packages/react-reconciler/src/ReactFiberHooks.js
+28 -30
@@ -247,7 +247,6 @@ function checkDepsAreArrayDev(deps: mixed) {
247 // Verify deps, but only on mount to avoid extra checks.
248 // It's unlikely their type would change as usually you define them inline.
249 warning(
250 - false,
250 '%s received a final argument that is not an array (instead, received `%s`). When ' +
251 'specified, the final argument must be an array.',
252 currentHookNameInDev,
@@ -289,7 +288,6 @@ function warnOnHookMismatchInDev(currentHookName: HookType) {
288 }
289
290 warning(
292 - false,
291 'React has detected a change in the order of Hooks called by %s. ' +
292 'This will lead to bugs and errors if not fixed. ' +
293 'For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n' +
@@ -331,7 +329,6 @@ function areHookInputsEqual(
329 if (prevDeps === null) {
330 if (__DEV__) {
331 warning(
334 - false,
332 '%s received a final argument during this render, but not during ' +
333 'the previous render. Even though the final argument is optional, ' +
334 'its type cannot change between renders.',
@@ -346,7 +343,6 @@ function areHookInputsEqual(
343 // passed inline.
344 if (nextDeps.length !== prevDeps.length) {
345 warning(
349 - false,
346 'The final argument passed to %s changed size between renders. The ' +
347 'order and size of this array must remain constant.\n\n' +
348 'Previous: %s\n' +
@@ -1008,12 +1004,13 @@ function imperativeHandleEffect<T>(
1004 } else if (ref !== null && ref !== undefined) {
1005 const refObject = ref;
1006 if (__DEV__) {
1011 - warning(
1012 - refObject.hasOwnProperty('current'),
1013 - 'Expected useImperativeHandle() first argument to either be a ' +
1014 - 'ref callback or React.createRef() object. Instead received: %s.',
1015 - 'an object with keys {' + Object.keys(refObject).join(', ') + '}',
1016 - );
1007 + if (!refObject.hasOwnProperty('current')) {
1008 + warning(
1009 + 'Expected useImperativeHandle() first argument to either be a ' +
1010 + 'ref callback or React.createRef() object. Instead received: %s.',
1011 + 'an object with keys {' + Object.keys(refObject).join(', ') + '}',
1012 + );
1013 + }
1014 }
1015 const inst = create();
1016 refObject.current = inst;
@@ -1029,12 +1026,13 @@ function mountImperativeHandle<T>(
1026 deps: Array<mixed> | void | null,
1027 ): void {
1028 if (__DEV__) {
1032 - warning(
1033 - typeof create === 'function',
1034 - 'Expected useImperativeHandle() second argument to be a function ' +
1035 - 'that creates a handle. Instead received: %s.',
1036 - create !== null ? typeof create : 'null',
1037 - );
1029 + if (typeof create !== 'function') {
1030 + warning(
1031 + 'Expected useImperativeHandle() second argument to be a function ' +
1032 + 'that creates a handle. Instead received: %s.',
1033 + create !== null ? typeof create : 'null',
1034 + );
1035 + }
1036 }
1037
1038 // TODO: If deps are provided, should we skip comparing the ref itself?
@@ -1055,12 +1053,13 @@ function updateImperativeHandle<T>(
1053 deps: Array<mixed> | void | null,
1054 ): void {
1055 if (__DEV__) {
1058 - warning(
1059 - typeof create === 'function',
1060 - 'Expected useImperativeHandle() second argument to be a function ' +
1061 - 'that creates a handle. Instead received: %s.',
1062 - create !== null ? typeof create : 'null',
1063 - );
1056 + if (typeof create !== 'function') {
1057 + warning(
1058 + 'Expected useImperativeHandle() second argument to be a function ' +
1059 + 'that creates a handle. Instead received: %s.',
1060 + create !== null ? typeof create : 'null',
1061 + );
1062 + }
1063 }
1064
1065 // TODO: If deps are provided, should we skip comparing the ref itself?
@@ -1235,12 +1234,13 @@ function dispatchAction<S, A>(
1234 );
1235
1236 if (__DEV__) {
1238 - warning(
1239 - typeof arguments[3] !== 'function',
1240 - "State updates from the useState() and useReducer() Hooks don't support the " +
1241 - 'second callback argument. To execute a side effect after ' +
1242 - 'rendering, declare it in the component body with useEffect().',
1243 - );
1237 + if (typeof arguments[3] === 'function') {
1238 + warning(
1239 + "State updates from the useState() and useReducer() Hooks don't support the " +
1240 + 'second callback argument. To execute a side effect after ' +
1241 + 'rendering, declare it in the component body with useEffect().',
1242 + );
1243 + }
1244 }
1245
1246 const alternate = fiber.alternate;
@@ -1423,7 +1423,6 @@ let InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher | null = null;
1423 if (__DEV__) {
1424 const warnInvalidContextAccess = () => {
1425 warning(
1426 - false,
1426 'Context can only be read while React is rendering. ' +
1427 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
1428 'In function components, you can read it directly in the function body, but not ' +
@@ -1433,7 +1432,6 @@ if (__DEV__) {
1432
1433 const warnInvalidHookAccess = () => {
1434 warning(
1436 - false,
1435 'Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' +
1436 'You can only call Hooks at the top level of your React function. ' +
1437 'For more information, see ' +
packages/react-reconciler/src/ReactFiberHostConfig.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -/* eslint-disable react-internal/warning-and-invariant-args */
10 +/* eslint-disable react-internal/invariant-args */
11
12 import invariant from 'shared/invariant';
13
packages/react-reconciler/src/ReactFiberHydrationContext.js
+5 -4
@@ -66,10 +66,11 @@ let isHydrating: boolean = false;
66
67 function warnIfHydrating() {
68 if (__DEV__) {
69 - warning(
70 - !isHydrating,
71 - 'We should not be hydrating here. This is a bug in React. Please file a bug.',
72 - );
69 + if (isHydrating) {
70 + warning(
71 + 'We should not be hydrating here. This is a bug in React. Please file a bug.',
72 + );
73 + }
74 }
75 }
76
packages/react-reconciler/src/ReactFiberNewContext.js
+35 -27
@@ -85,13 +85,16 @@ export function pushProvider<T>(providerFiber: Fiber, nextValue: T): void {
85
86 context._currentValue = nextValue;
87 if (__DEV__) {
88 - warningWithoutStack(
89 - context._currentRenderer === undefined ||
90 - context._currentRenderer === null ||
91 - context._currentRenderer === rendererSigil,
92 - 'Detected multiple renderers concurrently rendering the ' +
93 - 'same context provider. This is currently unsupported.',
94 - );
88 + if (
89 + context._currentRenderer !== undefined &&
90 + context._currentRenderer !== null &&
91 + context._currentRenderer !== rendererSigil
92 + ) {
93 + warningWithoutStack(
94 + 'Detected multiple renderers concurrently rendering the ' +
95 + 'same context provider. This is currently unsupported.',
96 + );
97 + }
98 context._currentRenderer = rendererSigil;
99 }
100 } else {
@@ -99,13 +102,16 @@ export function pushProvider<T>(providerFiber: Fiber, nextValue: T): void {
102
103 context._currentValue2 = nextValue;
104 if (__DEV__) {
102 - warningWithoutStack(
103 - context._currentRenderer2 === undefined ||
104 - context._currentRenderer2 === null ||
105 - context._currentRenderer2 === rendererSigil,
106 - 'Detected multiple renderers concurrently rendering the ' +
107 - 'same context provider. This is currently unsupported.',
108 - );
105 + if (
106 + context._currentRenderer2 !== undefined &&
107 + context._currentRenderer2 !== null &&
108 + context._currentRenderer2 !== rendererSigil
109 + ) {
110 + warningWithoutStack(
111 + 'Detected multiple renderers concurrently rendering the ' +
112 + 'same context provider. This is currently unsupported.',
113 + );
114 + }
115 context._currentRenderer2 = rendererSigil;
116 }
117 }
@@ -139,12 +145,13 @@ export function calculateChangedBits<T>(
145 : MAX_SIGNED_31_BIT_INT;
146
147 if (__DEV__) {
142 - warning(
143 - (changedBits & MAX_SIGNED_31_BIT_INT) === changedBits,
144 - 'calculateChangedBits: Expected the return value to be a ' +
145 - '31-bit integer. Instead received: %s',
146 - changedBits,
147 - );
148 + if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
149 + warning(
150 + 'calculateChangedBits: Expected the return value to be a ' +
151 + '31-bit integer. Instead received: %s',
152 + changedBits,
153 + );
154 + }
155 }
156 return changedBits | 0;
157 }
@@ -336,13 +343,14 @@ export function readContext<T>(
343 if (__DEV__) {
344 // This warning would fire if you read context inside a Hook like useMemo.
345 // Unlike the class check below, it's not enforced in production for perf.
339 - warning(
340 - !isDisallowedContextReadInDEV,
341 - 'Context can only be read while React is rendering. ' +
342 - 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
343 - 'In function components, you can read it directly in the function body, but not ' +
344 - 'inside Hooks like useReducer() or useMemo().',
345 - );
346 + if (isDisallowedContextReadInDEV) {
347 + warning(
348 + 'Context can only be read while React is rendering. ' +
349 + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
350 + 'In function components, you can read it directly in the function body, but not ' +
351 + 'inside Hooks like useReducer() or useMemo().',
352 + );
353 + }
354 }
355
356 if (lastContextWithAllBitsObserved === context) {
packages/react-reconciler/src/ReactFiberReconciler.js
+7 -9
@@ -182,7 +182,6 @@ function findHostInstanceWithWarning(
182 didWarnAboutFindNodeInStrictMode[componentName] = true;
183 if (fiber.mode & StrictMode) {
184 warningWithoutStack(
185 - false,
185 '%s is deprecated in StrictMode. ' +
186 '%s was passed an instance of %s which is inside StrictMode. ' +
187 'Instead, add a ref directly to the element you want to reference. ' +
@@ -195,7 +194,6 @@ function findHostInstanceWithWarning(
194 );
195 } else {
196 warningWithoutStack(
198 - false,
197 '%s is deprecated in StrictMode. ' +
198 '%s was passed an instance of %s which renders StrictMode children. ' +
199 'Instead, add a ref directly to the element you want to reference. ' +
@@ -263,7 +261,6 @@ export function updateContainer(
261 ) {
262 didWarnAboutNestedUpdates = true;
263 warningWithoutStack(
266 - false,
264 'Render methods should be a pure function of props and state; ' +
265 'triggering nested component updates from render is not allowed. ' +
266 'If necessary, trigger nested updates in componentDidUpdate.\n\n' +
@@ -281,12 +278,13 @@ export function updateContainer(
278 callback = callback === undefined ? null : callback;
279 if (callback !== null) {
280 if (__DEV__) {
284 - warningWithoutStack(
285 - typeof callback === 'function',
286 - 'render(...): Expected the last optional `callback` argument to be a ' +
287 - 'function. Instead received: %s.',
288 - callback,
289 - );
281 + if (typeof callback !== 'function') {
282 + warningWithoutStack(
283 + 'render(...): Expected the last optional `callback` argument to be a ' +
284 + 'function. Instead received: %s.',
285 + callback,
286 + );
287 + }
288 }
289 update.callback = callback;
290 }
packages/react-reconciler/src/ReactFiberStack.js
+2 -3
@@ -38,14 +38,14 @@ function isEmpty(): boolean {
38 function pop<T>(cursor: StackCursor<T>, fiber: Fiber): void {
39 if (index < 0) {
40 if (__DEV__) {
41 - warningWithoutStack(false, 'Unexpected pop.');
41 + warningWithoutStack('Unexpected pop.');
42 }
43 return;
44 }
45
46 if (__DEV__) {
47 if (fiber !== fiberStack[index]) {
48 - warningWithoutStack(false, 'Unexpected Fiber popped.');
48 + warningWithoutStack('Unexpected Fiber popped.');
49 }
50 }
51
@@ -76,7 +76,6 @@ function checkThatStackIsEmpty() {
76 if (__DEV__) {
77 if (index !== -1) {
78 warningWithoutStack(
79 - false,
79 'Expected an empty stack. Something was not reset properly.',
80 );
81 }
packages/react-reconciler/src/ReactFiberThrow.js
+7 -6
@@ -124,12 +124,13 @@ function createClassErrorUpdate(
124 // If componentDidCatch is the only error boundary method defined,
125 // then it needs to call setState to recover from errors.
126 // If no state update is scheduled then the boundary will swallow the error.
127 - warningWithoutStack(
128 - fiber.expirationTime === Sync,
129 - '%s: Error boundaries should implement getDerivedStateFromError(). ' +
130 - 'In that method, return a state update to display an error message or fallback UI.',
131 - getComponentName(fiber.type) || 'Unknown',
132 - );
127 + if (fiber.expirationTime !== Sync) {
128 + warningWithoutStack(
129 + '%s: Error boundaries should implement getDerivedStateFromError(). ' +
130 + 'In that method, return a state update to display an error message or fallback UI.',
131 + getComponentName(fiber.type) || 'Unknown',
132 + );
133 + }
134 }
135 }
136 };
packages/react-reconciler/src/ReactFiberTreeReflection.js
+10 -9
@@ -97,15 +97,16 @@ export function isMounted(component: React$Component<any, any>): boolean {
97 if (owner !== null && owner.tag === ClassComponent) {
98 const ownerFiber: Fiber = owner;
99 const instance = ownerFiber.stateNode;
100 - warningWithoutStack(
101 - instance._warnedAboutRefsInRender,
102 - '%s is accessing isMounted inside its render() function. ' +
103 - 'render() should be a pure function of props and state. It should ' +
104 - 'never access something that requires stale data from the previous ' +
105 - 'render, such as refs. Move this logic to componentDidMount and ' +
106 - 'componentDidUpdate instead.',
107 - getComponentName(ownerFiber.type) || 'A component',
108 - );
100 + if (!instance._warnedAboutRefsInRender) {
101 + warningWithoutStack(
102 + '%s is accessing isMounted inside its render() function. ' +
103 + 'render() should be a pure function of props and state. It should ' +
104 + 'never access something that requires stale data from the previous ' +
105 + 'render, such as refs. Move this logic to componentDidMount and ' +
106 + 'componentDidUpdate instead.',
107 + getComponentName(ownerFiber.type) || 'A component',
108 + );
109 + }
110 instance._warnedAboutRefsInRender = true;
111 }
112 }
packages/react-reconciler/src/ReactFiberWorkLoop.js
+1 -13
@@ -1093,7 +1093,6 @@ export function flushDiscreteUpdates() {
1093 if (__DEV__) {
1094 if ((executionContext & RenderContext) !== NoContext) {
1095 warning(
1096 - false,
1096 'unstable_flushDiscreteUpdates: Cannot flush updates when React is ' +
1097 'already rendering.',
1098 );
@@ -2525,7 +2524,6 @@ function checkForNestedUpdates() {
2524 if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
2525 nestedPassiveUpdateCount = 0;
2526 warning(
2528 - false,
2527 'Maximum update depth exceeded. This can happen when a component ' +
2528 "calls setState inside useEffect, but useEffect either doesn't " +
2529 'have a dependency array, or one of the dependencies changes on ' +
@@ -2598,7 +2596,6 @@ function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
2596 didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
2597 }
2598 warningWithoutStack(
2601 - false,
2599 "Can't perform a React state update on an unmounted component. This " +
2600 'is a no-op, but it indicates a memory leak in your application. To ' +
2601 'fix, cancel all subscriptions and asynchronous tasks in %s.%s',
@@ -2690,7 +2687,6 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) {
2687 return;
2688 }
2689 warningWithoutStack(
2693 - false,
2690 'setState(...): Cannot call setState() inside getChildContext()',
2691 );
2692 didWarnAboutUpdateInGetChildContext = true;
@@ -2700,7 +2696,6 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) {
2696 return;
2697 }
2698 warningWithoutStack(
2703 - false,
2699 'Cannot update during an existing state transition (such as ' +
2700 'within `render`). Render methods should be a pure function of ' +
2701 'props and state.',
@@ -2723,7 +2718,6 @@ export function warnIfNotScopedWithMatchingAct(fiber: Fiber): void {
2718 IsThisRendererActing.current !== true
2719 ) {
2720 warningWithoutStack(
2726 - false,
2721 "It looks like you're using the wrong act() around your test interactions.\n" +
2722 'Be sure to use the matching version of act() corresponding to your renderer:\n\n' +
2723 '// for react-dom:\n' +
@@ -2751,7 +2745,6 @@ export function warnIfNotCurrentlyActingEffectsInDEV(fiber: Fiber): void {
2745 IsThisRendererActing.current === false
2746 ) {
2747 warningWithoutStack(
2754 - false,
2748 'An update to %s ran an effect, but was not wrapped in act(...).\n\n' +
2749 'When testing, code that causes React state updates should be ' +
2750 'wrapped into act(...):\n\n' +
@@ -2779,7 +2772,6 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber: Fiber): void {
2772 IsThisRendererActing.current === false
2773 ) {
2774 warningWithoutStack(
2782 - false,
2775 'An update to %s inside a test was not wrapped in act(...).\n\n' +
2776 'When testing, code that causes React state updates should be ' +
2777 'wrapped into act(...):\n\n' +
@@ -2816,7 +2808,6 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
2808 if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
2809 didWarnAboutUnmockedScheduler = true;
2810 warningWithoutStack(
2819 - false,
2811 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
2812 'to guarantee consistent behaviour across tests and browsers. ' +
2813 'For example, with jest: \n' +
@@ -2826,7 +2817,6 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
2817 } else if (warnAboutUnmockedScheduler === true) {
2818 didWarnAboutUnmockedScheduler = true;
2819 warningWithoutStack(
2829 - false,
2820 'Starting from React v17, the "scheduler" module will need to be mocked ' +
2821 'to guarantee consistent behaviour across tests and browsers. ' +
2822 'For example, with jest: \n' +
@@ -2937,7 +2927,6 @@ function flushSuspensePriorityWarningInDEV() {
2927
2928 if (componentNames.length > 0) {
2929 warningWithoutStack(
2940 - false,
2930 '%s triggered a user-blocking update that suspended.' +
2931 '\n\n' +
2932 'The fix is to split the update into multiple parts: a user-blocking ' +
@@ -2945,8 +2934,7 @@ function flushSuspensePriorityWarningInDEV() {
2934 'triggers the bulk of the changes.' +
2935 '\n\n' +
2936 'Refer to the documentation for useTransition to learn how ' +
2948 - 'to implement this pattern.',
2949 - // TODO: Add link to React docs with more information, once it exists
2937 + 'to implement this pattern.', // TODO: Add link to React docs with more information, once it exists
2938 componentNames.sort().join(', '),
2939 );
2940 }
packages/react-reconciler/src/ReactStrictModeWarnings.js
-8
@@ -192,7 +192,6 @@ if (__DEV__) {
192 UNSAFE_componentWillMountUniqueNames,
193 );
194 warningWithoutStack(
195 - false,
195 'Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' +
196 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
197 '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
@@ -206,7 +205,6 @@ if (__DEV__) {
205 UNSAFE_componentWillReceivePropsUniqueNames,
206 );
207 warningWithoutStack(
209 - false,
208 'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' +
209 'and may indicate bugs in your code. ' +
210 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
@@ -224,7 +222,6 @@ if (__DEV__) {
222 UNSAFE_componentWillUpdateUniqueNames,
223 );
224 warningWithoutStack(
227 - false,
225 'Using UNSAFE_componentWillUpdate in strict mode is not recommended ' +
226 'and may indicate bugs in your code. ' +
227 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
@@ -238,7 +235,6 @@ if (__DEV__) {
235 const sortedNames = setToSortedString(componentWillMountUniqueNames);
236
237 lowPriorityWarningWithoutStack(
241 - false,
238 'componentWillMount has been renamed, and is not recommended for use. ' +
239 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
240 '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
@@ -257,7 +253,6 @@ if (__DEV__) {
253 );
254
255 lowPriorityWarningWithoutStack(
260 - false,
256 'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
257 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
258 '* Move data fetching code or side effects to componentDidUpdate.\n' +
@@ -277,7 +272,6 @@ if (__DEV__) {
272 const sortedNames = setToSortedString(componentWillUpdateUniqueNames);
273
274 lowPriorityWarningWithoutStack(
280 - false,
275 'componentWillUpdate has been renamed, and is not recommended for use. ' +
276 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' +
277 '* Move data fetching code or side effects to componentDidUpdate.\n' +
@@ -303,7 +297,6 @@ if (__DEV__) {
297 const strictRoot = findStrictRoot(fiber);
298 if (strictRoot === null) {
299 warningWithoutStack(
306 - false,
300 'Expected to find a StrictMode component in a strict mode tree. ' +
301 'This error is likely caused by a bug in React. Please file an issue.',
302 );
@@ -345,7 +338,6 @@ if (__DEV__) {
338 );
339
340 warningWithoutStack(
348 - false,
341 'Legacy context API has been detected within a strict-mode tree.' +
342 '\n\nThe old API will be supported in all 16.x releases, but applications ' +
343 'using it should migrate to the new version.' +
packages/react-reconciler/src/ReactUpdateQueue.js
-1
@@ -229,7 +229,6 @@ export function enqueueUpdate<State>(fiber: Fiber, update: Update<State>) {
229 !didWarnUpdateInsideUpdate
230 ) {
231 warningWithoutStack(
232 - false,
232 'An update (setState, replaceState, or forceUpdate) was scheduled ' +
233 'from inside an update function. Update functions should be pure, ' +
234 'with zero side-effects. Consider using componentDidUpdate or a ' +
packages/react-server/src/ReactServerFormatConfig.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -/* eslint-disable react-internal/warning-and-invariant-args */
10 +/* eslint-disable react-internal/invariant-args */
11
12 import invariant from 'shared/invariant';
13
packages/react-server/src/ReactServerHostConfig.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -/* eslint-disable react-internal/warning-and-invariant-args */
10 +/* eslint-disable react-internal/invariant-args */
11
12 import invariant from 'shared/invariant';
13
packages/react-test-renderer/src/ReactShallowRenderer.js
-2
@@ -63,7 +63,6 @@ function areHookInputsEqual(
63 if (prevDeps === null) {
64 if (__DEV__) {
65 warning(
66 - false,
66 '%s received a final argument during this render, but not during ' +
67 'the previous render. Even though the final argument is optional, ' +
68 'its type cannot change between renders.',
@@ -78,7 +77,6 @@ function areHookInputsEqual(
77 // passed inline.
78 if (nextDeps.length !== prevDeps.length) {
79 warning(
81 - false,
80 'The final argument passed to %s changed size between renders. The ' +
81 'order and size of this array must remain constant.\n\n' +
82 'Previous: %s\n' +
packages/react-test-renderer/src/ReactTestHostConfig.js
+15 -13
@@ -82,13 +82,14 @@ export function appendChild(
82 child: Instance | TextInstance,
83 ): void {
84 if (__DEV__) {
85 - warning(
86 - Array.isArray(parentInstance.children),
87 - 'An invalid container has been provided. ' +
88 - 'This may indicate that another renderer is being used in addition to the test renderer. ' +
89 - '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
90 - 'This is not supported.',
91 - );
85 + if (!Array.isArray(parentInstance.children)) {
86 + warning(
87 + 'An invalid container has been provided. ' +
88 + 'This may indicate that another renderer is being used in addition to the test renderer. ' +
89 + '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
90 + 'This is not supported.',
91 + );
92 + }
93 }
94 const index = parentInstance.children.indexOf(child);
95 if (index !== -1) {
@@ -216,12 +217,13 @@ export function createTextInstance(
217 ): TextInstance {
218 if (__DEV__) {
219 if (enableFlareAPI) {
219 - warning(
220 - hostContext !== EVENT_COMPONENT_CONTEXT,
221 - 'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
222 - 'Wrap the child text "%s" in an element.',
223 - text,
224 - );
220 + if (hostContext === EVENT_COMPONENT_CONTEXT) {
221 + warning(
222 + 'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
223 + 'Wrap the child text "%s" in an element.',
224 + text,
225 + );
226 + }
227 }
228 }
229 return {
packages/react-test-renderer/src/ReactTestRendererAct.js
+7 -9
@@ -84,7 +84,6 @@ function act(callback: () => Thenable) {
84 if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
85 // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
86 warningWithoutStack(
87 - null,
87 'You seem to have overlapping act() calls, this is not supported. ' +
88 'Be sure to await previous act() calls before making a new one. ',
89 );
@@ -117,7 +116,6 @@ function act(callback: () => Thenable) {
116 .then(() => {
117 if (called === false) {
118 warningWithoutStack(
120 - null,
119 'You called act(async () => ...) without await. ' +
120 'This could lead to unexpected testing behaviour, interleaving multiple act ' +
121 'calls and mixing their scopes. You should - await act(async () => ...);',
@@ -164,12 +162,13 @@ function act(callback: () => Thenable) {
162 };
163 } else {
164 if (__DEV__) {
167 - warningWithoutStack(
168 - result === undefined,
169 - 'The callback passed to act(...) function ' +
170 - 'must return undefined, or a Promise. You returned %s',
171 - result,
172 - );
165 + if (result !== undefined) {
166 + warningWithoutStack(
167 + 'The callback passed to act(...) function ' +
168 + 'must return undefined, or a Promise. You returned %s',
169 + result,
170 + );
171 + }
172 }
173
174 // flush effects until none remain, and cleanup
@@ -193,7 +192,6 @@ function act(callback: () => Thenable) {
192 then(resolve: () => void) {
193 if (__DEV__) {
194 warningWithoutStack(
196 - false,
195 'Do not await the result of calling act(...) with sync logic, it is not a Promise.',
196 );
197 }
packages/react/src/ReactBaseClasses.js
-1
@@ -106,7 +106,6 @@ if (__DEV__) {
106 Object.defineProperty(Component.prototype, methodName, {
107 get: function() {
108 lowPriorityWarningWithoutStack(
109 - false,
109 '%s(...) is deprecated in plain JavaScript React classes. %s',
110 info[0],
111 info[1],
packages/react/src/ReactChildren.js
+7 -6
@@ -162,12 +162,13 @@ function traverseAllChildrenImpl(
162 if (__DEV__) {
163 // Warn about using Maps as children
164 if (iteratorFn === children.entries) {
165 - warning(
166 - didWarnAboutMaps,
167 - 'Using Maps as children is unsupported and will likely yield ' +
168 - 'unexpected results. Convert it to a sequence/iterable of keyed ' +
169 - 'ReactElements instead.',
170 - );
165 + if (!didWarnAboutMaps) {
166 + warning(
167 + 'Using Maps as children is unsupported and will likely yield ' +
168 + 'unexpected results. Convert it to a sequence/iterable of keyed ' +
169 + 'ReactElements instead.',
170 + );
171 + }
172 didWarnAboutMaps = true;
173 }
174 }
packages/react/src/ReactContext.js
+10 -9
@@ -22,13 +22,16 @@ export function createContext<T>(
22 calculateChangedBits = null;
23 } else {
24 if (__DEV__) {
25 - warningWithoutStack(
26 - calculateChangedBits === null ||
27 - typeof calculateChangedBits === 'function',
28 - 'createContext: Expected the optional second argument to be a ' +
29 - 'function. Instead received: %s',
30 - calculateChangedBits,
31 - );
25 + if (
26 + calculateChangedBits !== null &&
27 + typeof calculateChangedBits !== 'function'
28 + ) {
29 + warningWithoutStack(
30 + 'createContext: Expected the optional second argument to be a ' +
31 + 'function. Instead received: %s',
32 + calculateChangedBits,
33 + );
34 + }
35 }
36 }
37
@@ -74,7 +77,6 @@ export function createContext<T>(
77 if (!hasWarnedAboutUsingConsumerProvider) {
78 hasWarnedAboutUsingConsumerProvider = true;
79 warning(
77 - false,
80 'Rendering <Context.Consumer.Provider> is not supported and will be removed in ' +
81 'a future major release. Did you mean to render <Context.Provider> instead?',
82 );
@@ -114,7 +116,6 @@ export function createContext<T>(
116 if (!hasWarnedAboutUsingNestedContextConsumers) {
117 hasWarnedAboutUsingNestedContextConsumers = true;
118 warning(
117 - false,
119 'Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' +
120 'a future major release. Did you mean to render <Context.Consumer> instead?',
121 );
packages/react/src/ReactElement.js
-2
@@ -52,7 +52,6 @@ function defineKeyPropWarningGetter(props, displayName) {
52 if (!specialPropKeyWarningShown) {
53 specialPropKeyWarningShown = true;
54 warningWithoutStack(
55 - false,
55 '%s: `key` is not a prop. Trying to access it will result ' +
56 'in `undefined` being returned. If you need to access the same ' +
57 'value within the child component, you should pass it as a different ' +
@@ -75,7 +74,6 @@ function defineRefPropWarningGetter(props, displayName) {
74 if (!specialPropRefWarningShown) {
75 specialPropRefWarningShown = true;
76 warningWithoutStack(
78 - false,
77 '%s: `ref` is not a prop. Trying to access it will result ' +
78 'in `undefined` being returned. If you need to access the same ' +
79 'value within the child component, you should pass it as a different ' +
packages/react/src/ReactElementValidator.js
+5 -11
@@ -134,7 +134,6 @@ function validateExplicitKey(element, parentType) {
134 setCurrentlyValidatingElement(element);
135 if (__DEV__) {
136 warning(
137 - false,
137 'Each child in a list should have a unique "key" prop.' +
138 '%s%s See https://fb.me/react-warning-keys for more information.',
139 currentComponentErrorInfo,
@@ -227,14 +226,15 @@ function validatePropTypes(element) {
226 } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
227 propTypesMisspellWarningShown = true;
228 warningWithoutStack(
230 - false,
229 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?',
230 name || 'Unknown',
231 );
232 }
235 - if (typeof type.getDefaultProps === 'function') {
233 + if (
234 + typeof type.getDefaultProps === 'function' &&
235 + !type.getDefaultProps.isReactClassApproved
236 + ) {
237 warningWithoutStack(
237 - type.getDefaultProps.isReactClassApproved,
238 'getDefaultProps is only used on classic React.createClass ' +
239 'definitions. Use a static property named `defaultProps` instead.',
240 );
@@ -255,7 +255,6 @@ function validateFragmentProps(fragment) {
255 const key = keys[i];
256 if (key !== 'children' && key !== 'key') {
257 warning(
258 - false,
258 'Invalid prop `%s` supplied to `React.Fragment`. ' +
259 'React.Fragment can only have `key` and `children` props.',
260 key,
@@ -265,7 +264,7 @@ function validateFragmentProps(fragment) {
264 }
265
266 if (fragment.ref !== null) {
268 - warning(false, 'Invalid attribute `ref` supplied to `React.Fragment`.');
267 + warning('Invalid attribute `ref` supplied to `React.Fragment`.');
268 }
269
270 setCurrentlyValidatingElement(null);
@@ -319,7 +318,6 @@ export function jsxWithValidation(
318
319 if (__DEV__) {
320 warning(
322 - false,
321 'React.jsx: type is invalid -- expected a string (for ' +
322 'built-in components) or a class/function (for composite ' +
323 'components) but got: %s.%s',
@@ -358,7 +356,6 @@ export function jsxWithValidation(
356 } else {
357 if (__DEV__) {
358 warning(
361 - false,
359 'React.jsx: Static children should always be an array. ' +
360 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' +
361 'Use the Babel transform instead.',
@@ -374,7 +371,6 @@ export function jsxWithValidation(
371 if (hasOwnProperty.call(props, 'key')) {
372 if (__DEV__) {
373 warning(
377 - false,
374 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' +
375 'Explicitly pass a key after spreading props in your JSX call. ' +
376 'E.g. <ComponentName {...props} key={key} />',
@@ -443,7 +439,6 @@ export function createElementWithValidation(type, props, children) {
439
440 if (__DEV__) {
441 warning(
446 - false,
442 'React.createElement: type is invalid -- expected a string (for ' +
443 'built-in components) or a class/function (for composite ' +
444 'components) but got: %s.%s',
@@ -490,7 +485,6 @@ export function createFactoryWithValidation(type) {
485 enumerable: false,
486 get: function() {
487 lowPriorityWarningWithoutStack(
493 - false,
488 'Factory.type is deprecated. Access the class directly ' +
489 'before passing it to createFactory.',
490 );
packages/react/src/ReactHooks.js
+13 -15
@@ -38,18 +38,19 @@ export function useContext<T>(
38 ) {
39 const dispatcher = resolveDispatcher();
40 if (__DEV__) {
41 - warning(
42 - unstable_observedBits === undefined,
43 - 'useContext() second argument is reserved for future ' +
44 - 'use in React. Passing it is not supported. ' +
45 - 'You passed: %s.%s',
46 - unstable_observedBits,
47 - typeof unstable_observedBits === 'number' && Array.isArray(arguments[2])
48 - ? '\n\nDid you call array.map(useContext)? ' +
49 - 'Calling Hooks inside a loop is not supported. ' +
50 - 'Learn more at https://fb.me/rules-of-hooks'
51 - : '',
52 - );
41 + if (unstable_observedBits !== undefined) {
42 + warning(
43 + 'useContext() second argument is reserved for future ' +
44 + 'use in React. Passing it is not supported. ' +
45 + 'You passed: %s.%s',
46 + unstable_observedBits,
47 + typeof unstable_observedBits === 'number' && Array.isArray(arguments[2])
48 + ? '\n\nDid you call array.map(useContext)? ' +
49 + 'Calling Hooks inside a loop is not supported. ' +
50 + 'Learn more at https://fb.me/rules-of-hooks'
51 + : '',
52 + );
53 + }
54
55 // TODO: add a more generic warning for invalid values.
56 if ((Context: any)._context !== undefined) {
@@ -58,13 +59,11 @@ export function useContext<T>(
59 // and nobody should be using this in existing code.
60 if (realContext.Consumer === Context) {
61 warning(
61 - false,
62 'Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' +
63 'removed in a future major release. Did you mean to call useContext(Context) instead?',
64 );
65 } else if (realContext.Provider === Context) {
66 warning(
67 - false,
67 'Calling useContext(Context.Provider) is not supported. ' +
68 'Did you mean to call useContext(Context) instead?',
69 );
@@ -151,7 +150,6 @@ export function useResponder(
150 if (__DEV__) {
151 if (responder == null || responder.$$typeof !== REACT_RESPONDER_TYPE) {
152 warning(
154 - false,
153 'useResponder: invalid first argument. Expected an event responder, but instead got %s',
154 responder,
155 );
packages/react/src/ReactLazy.js
-2
@@ -31,7 +31,6 @@ export function lazy<T, R>(ctor: () => Thenable<T, R>): LazyComponent<T> {
31 },
32 set(newDefaultProps) {
33 warning(
34 - false,
34 'React.lazy(...): It is not supported to assign `defaultProps` to ' +
35 'a lazy component import. Either specify them where the component ' +
36 'is defined, or create a wrapping component around it.',
@@ -50,7 +49,6 @@ export function lazy<T, R>(ctor: () => Thenable<T, R>): LazyComponent<T> {
49 },
50 set(newPropTypes) {
51 warning(
53 - false,
52 'React.lazy(...): It is not supported to assign `propTypes` to ' +
53 'a lazy component import. Either specify them where the component ' +
54 'is defined, or create a wrapping component around it.',
packages/react/src/ReactNoopUpdateQueue.js
-1
@@ -20,7 +20,6 @@ function warnNoop(publicInstance, callerName) {
20 return;
21 }
22 warningWithoutStack(
23 - false,
23 "Can't call %s on a component that is not yet mounted. " +
24 'This is a no-op, but it might indicate a bug in your application. ' +
25 'Instead, assign to `this.state` directly or define a `state = {};` ' +
packages/react/src/forwardRef.js
+14 -15
@@ -15,34 +15,33 @@ export default function forwardRef<Props, ElementType: React$ElementType>(
15 if (__DEV__) {
16 if (render != null && render.$$typeof === REACT_MEMO_TYPE) {
17 warningWithoutStack(
18 - false,
18 'forwardRef requires a render function but received a `memo` ' +
19 'component. Instead of forwardRef(memo(...)), use ' +
20 'memo(forwardRef(...)).',
21 );
22 } else if (typeof render !== 'function') {
23 warningWithoutStack(
25 - false,
24 'forwardRef requires a render function but was given %s.',
25 render === null ? 'null' : typeof render,
26 );
27 } else {
30 - warningWithoutStack(
31 - // Do not warn for 0 arguments because it could be due to usage of the 'arguments' object
32 - render.length === 0 || render.length === 2,
33 - 'forwardRef render functions accept exactly two parameters: props and ref. %s',
34 - render.length === 1
35 - ? 'Did you forget to use the ref parameter?'
36 - : 'Any additional parameter will be undefined.',
37 - );
28 + if (render.length !== 0 && render.length !== 2) {
29 + warningWithoutStack(
30 + 'forwardRef render functions accept exactly two parameters: props and ref. %s',
31 + render.length === 1
32 + ? 'Did you forget to use the ref parameter?'
33 + : 'Any additional parameter will be undefined.',
34 + );
35 + }
36 }
37
38 if (render != null) {
41 - warningWithoutStack(
42 - render.defaultProps == null && render.propTypes == null,
43 - 'forwardRef render functions do not support propTypes or defaultProps. ' +
44 - 'Did you accidentally pass a React component?',
45 - );
39 + if (render.defaultProps != null || render.propTypes != null) {
40 + warningWithoutStack(
41 + 'forwardRef render functions do not support propTypes or defaultProps. ' +
42 + 'Did you accidentally pass a React component?',
43 + );
44 + }
45 }
46 }
47
packages/react/src/memo.js
-1
@@ -17,7 +17,6 @@ export default function memo<Props>(
17 if (__DEV__) {
18 if (!isValidElementType(type)) {
19 warningWithoutStack(
20 - false,
20 'memo: The first argument must be a component. Instead ' +
21 'received: %s',
22 type === null ? 'null' : typeof type,
packages/shared/ReactLazyComponent.js
-1
@@ -53,7 +53,6 @@ export function initializeLazyComponentType(
53 if (__DEV__) {
54 if (defaultExport === undefined) {
55 warning(
56 - false,
56 'lazy: Expected the result of a dynamic import() call. ' +
57 'Instead received: %s\n\nYour code should look like: \n ' +
58 "const MyComponent = lazy(() => import('./MyComponent'))",
packages/shared/enqueueTask.js
+8 -7
@@ -27,13 +27,14 @@ try {
27 if (__DEV__) {
28 if (didWarnAboutMessageChannel === false) {
29 didWarnAboutMessageChannel = true;
30 - warningWithoutStack(
31 - typeof MessageChannel !== 'undefined',
32 - 'This browser does not have a MessageChannel implementation, ' +
33 - 'so enqueuing tasks via await act(async () => ...) will fail. ' +
34 - 'Please file an issue at https://github.com/facebook/react/issues ' +
35 - 'if you encounter this warning.',
36 - );
30 + if (typeof MessageChannel === 'undefined') {
31 + warningWithoutStack(
32 + 'This browser does not have a MessageChannel implementation, ' +
33 + 'so enqueuing tasks via await act(async () => ...) will fail. ' +
34 + 'Please file an issue at https://github.com/facebook/react/issues ' +
35 + 'if you encounter this warning.',
36 + );
37 + }
38 }
39 }
40 const channel = new MessageChannel();
packages/shared/forks/lowPriorityWarningWithoutStack.www.js
+6 -2
@@ -5,5 +5,9 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -// This "lowPriorityWarning" is an external module
9 -export default require('lowPriorityWarning');
8 +// This refers to a WWW module.
9 +const lowPriorityWarningWWW = require('lowPriorityWarning');
10 +
11 +export default function lowPriorityWarningWithoutStack(format, ...args) {
12 + return lowPriorityWarningWWW(false, format, ...args);
13 +}
packages/shared/forks/warningWithoutStack.www.js
+6 -1
@@ -5,4 +5,9 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -export default require('warning');
8 +// This refers to a WWW module.
9 +const warningWWW = require('warning');
10 +
11 +export default function warningWithoutStack(format, ...args) {
12 + return warningWWW(false, format, ...args);
13 +}
packages/shared/getComponentName.js
-1
@@ -45,7 +45,6 @@ function getComponentName(type: mixed): string | null {
45 if (__DEV__) {
46 if (typeof (type: any).tag === 'number') {
47 warningWithoutStack(
48 - false,
48 'Received an unexpected object in getComponentName(). ' +
49 'This is likely a bug in React. Please file an issue.',
50 );
packages/shared/lowPriorityWarning.js
+3 -6
@@ -18,14 +18,11 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
18 let lowPriorityWarning = lowPriorityWarningWithoutStack;
19
20 if (__DEV__) {
21 - lowPriorityWarning = function(condition, format, ...args) {
22 - if (condition) {
23 - return;
24 - }
21 + lowPriorityWarning = function(format, ...args) {
22 const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
23 const stack = ReactDebugCurrentFrame.getStackAddendum();
27 - // eslint-disable-next-line react-internal/warning-and-invariant-args
28 - lowPriorityWarningWithoutStack(false, format + '%s', ...args, stack);
24 + // eslint-disable-next-line react-internal/warning-args
25 + lowPriorityWarningWithoutStack(format + '%s', ...args, stack);
26 };
27 }
28
packages/shared/lowPriorityWarningWithoutStack.js
+3 -4
@@ -36,16 +36,15 @@ if (__DEV__) {
36 } catch (x) {}
37 };
38
39 - lowPriorityWarningWithoutStack = function(condition, format, ...args) {
39 + lowPriorityWarningWithoutStack = function(format, ...args) {
40 if (format === undefined) {
41 throw new Error(
42 '`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' +
43 'message argument',
44 );
45 }
46 - if (!condition) {
47 - printWarning(format, ...args);
48 - }
46 +
47 + printWarning(format, ...args);
48 };
49 }
50
packages/shared/warning.js
+3 -6
@@ -18,14 +18,11 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
18 let warning = warningWithoutStack;
19
20 if (__DEV__) {
21 - warning = function(condition, format, ...args) {
22 - if (condition) {
23 - return;
24 - }
21 + warning = function(format, ...args) {
22 const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
23 const stack = ReactDebugCurrentFrame.getStackAddendum();
27 - // eslint-disable-next-line react-internal/warning-and-invariant-args
28 - warningWithoutStack(false, format + '%s', ...args, stack);
24 + // eslint-disable-next-line react-internal/warning-args
25 + warningWithoutStack(format + '%s', ...args, stack);
26 };
27 }
28
packages/shared/warningWithoutStack.js
+1 -5
@@ -6,7 +6,6 @@
6 */
7
8 /**
9 - * Similar to invariant but only logs a warning if the condition is not met.
9 * This can be used to log issues in development environments in critical
10 * paths. Removing the logging code for production environments will keep the
11 * same logic and follow the same code paths.
@@ -15,7 +14,7 @@
14 let warningWithoutStack = () => {};
15
16 if (__DEV__) {
18 - warningWithoutStack = function(condition, format, ...args) {
17 + warningWithoutStack = function(format, ...args) {
18 if (format === undefined) {
19 throw new Error(
20 '`warningWithoutStack(condition, format, ...args)` requires a warning ' +
@@ -28,9 +27,6 @@ if (__DEV__) {
27 'warningWithoutStack() currently supports at most 8 arguments.',
28 );
29 }
31 - if (condition) {
32 - return;
33 - }
30 if (typeof console !== 'undefined') {
31 const argsWithFormat = args.map(item => '' + item);
32 argsWithFormat.unshift('Warning: ' + format);
scripts/babel/__tests__/lift-warning-conditional-argument-test.js deleted
-56
@@ -1,56 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -/* eslint-disable quotes */
8 -'use strict';
9 -
10 -let babel = require('@babel/core');
11 -let wrapWarningWithEnvCheck = require('../lift-warning-conditional-argument');
12 -
13 -function transform(input) {
14 - return babel.transform(input, {
15 - plugins: [wrapWarningWithEnvCheck],
16 - }).code;
17 -}
18 -
19 -function compare(input, output) {
20 - const compiled = transform(input);
21 - expect(compiled).toEqual(output);
22 -}
23 -
24 -let oldEnv;
25 -
26 -describe('lift-warning-conditional-argument', () => {
27 - beforeEach(() => {
28 - oldEnv = process.env.NODE_ENV;
29 - process.env.NODE_ENV = '';
30 - });
31 -
32 - afterEach(() => {
33 - process.env.NODE_ENV = oldEnv;
34 - });
35 -
36 - it('should wrap warning calls', () => {
37 - compare(
38 - "warning(condition, 'a %s b', 'c');",
39 - "!condition ? warning(false, 'a %s b', 'c') : void 0;"
40 - );
41 - });
42 -
43 - it('should wrap warningWithoutStack calls', () => {
44 - compare(
45 - "warningWithoutStack(condition, 'a %s b', 'c');",
46 - "!condition ? warningWithoutStack(false, 'a %s b', 'c') : void 0;"
47 - );
48 - });
49 -
50 - it('should not wrap invariant calls', () => {
51 - compare(
52 - "invariant(condition, 'a %s b', 'c');",
53 - "invariant(condition, 'a %s b', 'c');"
54 - );
55 - });
56 -});
scripts/babel/lift-warning-conditional-argument.js deleted
-58
@@ -1,58 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -'use strict';
8 -
9 -module.exports = function(babel, options) {
10 - const t = babel.types;
11 -
12 - const SEEN_SYMBOL = Symbol('expression.seen');
13 -
14 - return {
15 - visitor: {
16 - CallExpression: {
17 - exit: function(path) {
18 - const node = path.node;
19 -
20 - // Ignore if it's already been processed
21 - if (node[SEEN_SYMBOL]) {
22 - return;
23 - }
24 -
25 - if (
26 - path.get('callee').isIdentifier({name: 'warning'}) ||
27 - path.get('callee').isIdentifier({name: 'warningWithoutStack'})
28 - ) {
29 - // Turns this code:
30 - //
31 - // warning(condition, argument, argument);
32 - //
33 - // into this:
34 - //
35 - // if (!condition) {
36 - // warning(false, argument, argument);
37 - // }
38 - //
39 - // The goal is to strip out warning calls entirely in production
40 - // and to avoid evaluating the arguments in development.
41 - const condition = node.arguments[0];
42 - const newNode = t.callExpression(
43 - node.callee,
44 - [t.booleanLiteral(false)].concat(node.arguments.slice(1))
45 - );
46 - newNode[SEEN_SYMBOL] = true;
47 - path.replaceWith(
48 - t.ifStatement(
49 - t.unaryExpression('!', condition),
50 - t.expressionStatement(newNode)
51 - )
52 - );
53 - }
54 - },
55 - },
56 - },
57 - };
58 -};
scripts/eslint-rules/__tests__/invariant-args-test.internal.js renamed
+9 -41
@@ -9,14 +9,12 @@
9
10 'use strict';
11
12 -const rule = require('../warning-and-invariant-args');
12 +const rule = require('../invariant-args');
13 const RuleTester = require('eslint').RuleTester;
14 const ruleTester = new RuleTester();
15
16 -ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
16 +ruleTester.run('eslint-rules/invariant-args', rule, {
17 valid: [
18 - "warning(true, 'hello, world');",
19 - "warning(true, 'expected %s, got %s', 42, 24);",
18 'arbitraryFunction(a, b)',
19 // These messages are in the error code map
20 "invariant(false, 'Do not override existing functions.')",
@@ -24,18 +22,18 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
22 ],
23 invalid: [
24 {
27 - code: "warning('hello, world');",
25 + code: "invariant('hello, world');",
26 errors: [
27 {
30 - message: 'warning takes at least two arguments',
28 + message: 'invariant takes at least two arguments',
29 },
30 ],
31 },
32 {
35 - code: 'warning(true, null);',
33 + code: 'invariant(true, null);',
34 errors: [
35 {
38 - message: 'The second argument to warning must be a string literal',
36 + message: 'The second argument to invariant must be a string literal',
37 },
38 ],
39 },
@@ -47,26 +45,6 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
45 },
46 ],
47 },
50 - {
51 - code: "warning(true, 'expected %s, got %s');",
52 - errors: [
53 - {
54 - message:
55 - 'Expected 4 arguments in call to warning based on the number of ' +
56 - '"%s" substitutions, but got 2',
57 - },
58 - ],
59 - },
60 - {
61 - code: "warning(true, 'foo is a bar under foobar', 'junk argument');",
62 - errors: [
63 - {
64 - message:
65 - 'Expected 2 arguments in call to warning based on the number of ' +
66 - '"%s" substitutions, but got 3',
67 - },
68 - ],
69 - },
48 {
49 code: "invariant(true, 'error!');",
50 errors: [
@@ -78,22 +56,12 @@ ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
56 ],
57 },
58 {
81 - code: "warning(true, 'error!');",
59 + code: "invariant(true, '%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
60 errors: [
61 {
62 message:
85 - 'The warning format should be able to uniquely identify this ' +
86 - 'warning. Please, use a more descriptive format than: error!',
87 - },
88 - ],
89 - },
90 - {
91 - code: "warning(true, '%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
92 - errors: [
93 - {
94 - message:
95 - 'The warning format should be able to uniquely identify this ' +
96 - 'warning. Please, use a more descriptive format than: ' +
63 + 'The invariant format should be able to uniquely identify this ' +
64 + 'invariant. Please, use a more descriptive format than: ' +
65 '%s %s, %s %s: %s (%s)',
66 },
67 ],
scripts/eslint-rules/__tests__/warning-args-test.internal.js new
+81
@@ -0,0 +1,81 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @emails react-core
8 + */
9 +
10 +'use strict';
11 +
12 +const rule = require('../warning-args');
13 +const RuleTester = require('eslint').RuleTester;
14 +const ruleTester = new RuleTester();
15 +
16 +ruleTester.run('eslint-rules/warning-args', rule, {
17 + valid: [
18 + "warning('hello, world');",
19 + "warning('expected %s, got %s', 42, 24);",
20 + 'arbitraryFunction(a, b)',
21 + ],
22 + invalid: [
23 + {
24 + code: 'warning(null);',
25 + errors: [
26 + {
27 + message: 'The first argument to warning must be a string literal',
28 + },
29 + ],
30 + },
31 + {
32 + code: 'var g = 5; warning(g);',
33 + errors: [
34 + {
35 + message: 'The first argument to warning must be a string literal',
36 + },
37 + ],
38 + },
39 + {
40 + code: "warning('expected %s, got %s');",
41 + errors: [
42 + {
43 + message:
44 + 'Expected 3 arguments in call to warning based on the number of ' +
45 + '"%s" substitutions, but got 1',
46 + },
47 + ],
48 + },
49 + {
50 + code: "warning('foo is a bar under foobar', 'junk argument');",
51 + errors: [
52 + {
53 + message:
54 + 'Expected 1 arguments in call to warning based on the number of ' +
55 + '"%s" substitutions, but got 2',
56 + },
57 + ],
58 + },
59 + {
60 + code: "warning('error!');",
61 + errors: [
62 + {
63 + message:
64 + 'The warning format should be able to uniquely identify this ' +
65 + 'warning. Please, use a more descriptive format than: error!',
66 + },
67 + ],
68 + },
69 + {
70 + code: "warning('%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
71 + errors: [
72 + {
73 + message:
74 + 'The warning format should be able to uniquely identify this ' +
75 + 'warning. Please, use a more descriptive format than: ' +
76 + '%s %s, %s %s: %s (%s)',
77 + },
78 + ],
79 + },
80 + ],
81 +});
scripts/eslint-rules/index.js
+2 -1
@@ -4,7 +4,8 @@ module.exports = {
4 rules: {
5 'no-primitive-constructors': require('./no-primitive-constructors'),
6 'no-to-warn-dev-within-to-throw': require('./no-to-warn-dev-within-to-throw'),
7 - 'warning-and-invariant-args': require('./warning-and-invariant-args'),
7 + 'warning-args': require('./warning-args'),
8 + 'invariant-args': require('./invariant-args'),
9 'no-production-logging': require('./no-production-logging'),
10 },
11 };
scripts/eslint-rules/invariant-args.js renamed
+14 -19
@@ -43,12 +43,9 @@ module.exports = function(context) {
43 CallExpression: function(node) {
44 // This could be a little smarter by checking context.getScope() to see
45 // how warning/invariant was defined.
46 - const isWarningOrInvariant =
47 - node.callee.type === 'Identifier' &&
48 - (node.callee.name === 'warning' ||
49 - node.callee.name === 'warningWithoutStack' ||
50 - node.callee.name === 'invariant');
51 - if (!isWarningOrInvariant) {
46 + const isInvariant =
47 + node.callee.type === 'Identifier' && node.callee.name === 'invariant';
48 + if (!isInvariant) {
49 return;
50 }
51 if (node.arguments.length < 2) {
@@ -90,19 +87,17 @@ module.exports = function(context) {
87 );
88 }
89
93 - if (node.callee.name === 'invariant') {
94 - if (!messages.has(format)) {
95 - context.report(
96 - node,
97 - 'Error message does not have a corresponding production ' +
98 - 'error code.\n\n' +
99 - 'Run `yarn extract-errors` to add the message to error code ' +
100 - 'map, so it can be stripped from the production builds. ' +
101 - "Alternatively, if you're updating an existing error " +
102 - 'message, you can modify ' +
103 - '`scripts/error-codes/codes.json` directly.'
104 - );
105 - }
90 + if (!messages.has(format)) {
91 + context.report(
92 + node,
93 + 'Error message does not have a corresponding production ' +
94 + 'error code.\n\n' +
95 + 'Run `yarn extract-errors` to add the message to error code ' +
96 + 'map, so it can be stripped from the production builds. ' +
97 + "Alternatively, if you're updating an existing error " +
98 + 'message, you can modify ' +
99 + '`scripts/error-codes/codes.json` directly.'
100 + );
101 }
102 },
103 };
scripts/eslint-rules/warning-args.js new
+97
@@ -0,0 +1,97 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @emails react-core
8 + */
9 +
10 +'use strict';
11 +
12 +const fs = require('fs');
13 +const path = require('path');
14 +const existingErrorMap = JSON.parse(
15 + fs.readFileSync(path.resolve(__dirname, '../error-codes/codes.json'))
16 +);
17 +const messages = new Set();
18 +Object.keys(existingErrorMap).forEach(key =>
19 + messages.add(existingErrorMap[key])
20 +);
21 +
22 +/**
23 + * The warning() function takes format strings as its second
24 + * argument.
25 + */
26 +
27 +module.exports = function(context) {
28 + // we also allow literal strings and concatenated literal strings
29 + function getLiteralString(node) {
30 + if (node.type === 'Literal' && typeof node.value === 'string') {
31 + return node.value;
32 + } else if (node.type === 'BinaryExpression' && node.operator === '+') {
33 + const l = getLiteralString(node.left);
34 + const r = getLiteralString(node.right);
35 + if (l !== null && r !== null) {
36 + return l + r;
37 + }
38 + }
39 + return null;
40 + }
41 +
42 + return {
43 + CallExpression: function(node) {
44 + // This could be a little smarter by checking context.getScope() to see
45 + // how warning/invariant was defined.
46 + const isWarning =
47 + node.callee.type === 'Identifier' &&
48 + (node.callee.name === 'warning' ||
49 + node.callee.name === 'warningWithoutStack' ||
50 + node.callee.name === 'lowPriorityWarning' ||
51 + node.callee.name === 'lowPriorityWarningWithoutStack');
52 + if (!isWarning) {
53 + return;
54 + }
55 + if (node.arguments.length < 1) {
56 + context.report(node, '{{name}} takes at least one argument', {
57 + name: node.callee.name,
58 + });
59 + return;
60 + }
61 + const format = getLiteralString(node.arguments[0]);
62 + if (format === null) {
63 + context.report(
64 + node,
65 + 'The first argument to {{name}} must be a string literal',
66 + {name: node.callee.name}
67 + );
68 + return;
69 + }
70 + if (format.length < 10 || /^[s\W]*$/.test(format)) {
71 + context.report(
72 + node,
73 + 'The {{name}} format should be able to uniquely identify this ' +
74 + '{{name}}. Please, use a more descriptive format than: {{format}}',
75 + {name: node.callee.name, format: format}
76 + );
77 + return;
78 + }
79 + // count the number of formatting substitutions, plus the first two args
80 + const expectedNArgs = (format.match(/%s/g) || []).length + 1;
81 + if (node.arguments.length !== expectedNArgs) {
82 + context.report(
83 + node,
84 + 'Expected {{expectedNArgs}} arguments in call to {{name}} based on ' +
85 + 'the number of "%s" substitutions, but got {{length}}',
86 + {
87 + expectedNArgs: expectedNArgs,
88 + name: node.callee.name,
89 + length: node.arguments.length,
90 + }
91 + );
92 + }
93 + },
94 + };
95 +};
96 +
97 +module.exports.schema = [];
scripts/jest/preprocessor.js
-5
@@ -16,9 +16,6 @@ const pathToBabel = path.join(
16 const pathToBabelPluginDevWithCode = require.resolve(
17 '../error-codes/transform-error-messages'
18 );
19 -const pathToBabelPluginWrapWarning = require.resolve(
20 - '../babel/lift-warning-conditional-argument'
21 -);
19 const pathToBabelPluginAsyncToGenerator = require.resolve(
20 '@babel/plugin-transform-async-to-generator'
21 );
@@ -34,7 +31,6 @@ const babelOptions = {
31 require.resolve('@babel/plugin-transform-modules-commonjs'),
32
33 pathToBabelPluginDevWithCode,
37 - pathToBabelPluginWrapWarning,
34
35 // Keep stacks detailed in tests.
36 // Don't put this in .babelrc so that we don't embed filenames
@@ -92,7 +88,6 @@ module.exports = {
88 pathToBabel,
89 pathToBabelrc,
90 pathToBabelPluginDevWithCode,
95 - pathToBabelPluginWrapWarning,
91 pathToTransformInfiniteLoops,
92 pathToErrorCodes,
93 ]),
scripts/print-warnings/print-warnings.js
+1 -1
@@ -61,7 +61,7 @@ function transform(file, enc, cb) {
61 // warning messages can be concatenated (`+`) at runtime, so here's
62 // a trivial partial evaluator that interprets the literal value
63 try {
64 - const warningMsgLiteral = evalToString(node.arguments[1]);
64 + const warningMsgLiteral = evalToString(node.arguments[0]);
65 warnings.add(JSON.stringify(warningMsgLiteral));
66 } catch (error) {
67 console.error(
scripts/rollup/build.js
-6
@@ -124,8 +124,6 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
124 plugins: options.plugins.concat([
125 // Minify invariant messages
126 require('../error-codes/transform-error-messages'),
127 - // Wrap warning() calls in a __DEV__ check so they are stripped from production.
128 - require('../babel/lift-warning-conditional-argument'),
127 ]),
128 });
129 case RN_OSS_DEV:
@@ -141,8 +139,6 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
139 // Preserve full error messages in React Native build
140 {noMinify: true},
141 ],
144 - // Wrap warning() calls in a __DEV__ check so they are stripped from production.
145 - require('../babel/lift-warning-conditional-argument'),
142 ]),
143 });
144 case UMD_DEV:
@@ -157,8 +153,6 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
153 path.resolve('./scripts/babel/transform-object-assign-require'),
154 // Minify invariant messages
155 require('../error-codes/transform-error-messages'),
160 - // Wrap warning() calls in a __DEV__ check so they are stripped from production.
161 - require('../babel/lift-warning-conditional-argument'),
156 ]),
157 });
158 default:
scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js
+1 -1
@@ -8,7 +8,7 @@
8 * @flow strict-local
9 */
10
11 -/* eslint-disable react-internal/warning-and-invariant-args */
11 +/* eslint-disable react-internal/invariant-args */
12
13 'use strict';
14