Skip to content

Commit 9254e4a

Browse files
authored
Use console directly instead of warning() modules (#17599)
* Replace all warning/lowPriWarning with console calls * Replace console.warn/error with a custom wrapper at build time * Fail the build for console.error/warn() where we can't read the stack
1 parent 995a837 commit 9254e4a

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/ReactShallowRenderer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import shallowEqual from 'shared/shallowEqual';
1515
import invariant from 'shared/invariant';
1616
import checkPropTypes from 'prop-types/checkPropTypes';
1717
import ReactSharedInternals from 'shared/ReactSharedInternals';
18-
import warning from 'shared/warning';
1918
import is from 'shared/objectIs';
2019

2120
import type {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberHooks';
@@ -62,7 +61,7 @@ function areHookInputsEqual(
6261
) {
6362
if (prevDeps === null) {
6463
if (__DEV__) {
65-
warning(
64+
console.error(
6665
'%s received a final argument during this render, but not during ' +
6766
'the previous render. Even though the final argument is optional, ' +
6867
'its type cannot change between renders.',
@@ -76,7 +75,7 @@ function areHookInputsEqual(
7675
// Don't bother comparing lengths in prod because these arrays should be
7776
// passed inline.
7877
if (nextDeps.length !== prevDeps.length) {
79-
warning(
78+
console.error(
8079
'The final argument passed to %s changed size between renders. The ' +
8180
'order and size of this array must remain constant.\n\n' +
8281
'Previous: %s\n' +

src/ReactTestHostConfig.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow
88
*/
99

10-
import warning from 'shared/warning';
11-
1210
import type {
1311
ReactEventResponder,
1412
ReactEventResponderInstance,
@@ -83,7 +81,7 @@ export function appendChild(
8381
): void {
8482
if (__DEV__) {
8583
if (!Array.isArray(parentInstance.children)) {
86-
warning(
84+
console.error(
8785
'An invalid container has been provided. ' +
8886
'This may indicate that another renderer is being used in addition to the test renderer. ' +
8987
'(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
@@ -218,7 +216,7 @@ export function createTextInstance(
218216
if (__DEV__) {
219217
if (enableFlareAPI) {
220218
if (hostContext === EVENT_COMPONENT_CONTEXT) {
221-
warning(
219+
console.error(
222220
'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
223221
'Wrap the child text "%s" in an element.',
224222
text,

src/ReactTestRendererAct.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
IsThisRendererActing,
1515
} from 'react-reconciler/inline.test';
1616
import ReactSharedInternals from 'shared/ReactSharedInternals';
17-
import warning from 'shared/warning';
1817
import enqueueTask from 'shared/enqueueTask';
1918
import * as Scheduler from 'scheduler';
2019

@@ -61,6 +60,7 @@ function act(callback: () => Thenable) {
6160
if (!__DEV__) {
6261
if (didWarnAboutUsingActInProd === false) {
6362
didWarnAboutUsingActInProd = true;
63+
// eslint-disable-next-line react-internal/no-production-logging
6464
console.error(
6565
'act(...) is not supported in production builds of React, and might not behave as expected.',
6666
);
@@ -83,7 +83,7 @@ function act(callback: () => Thenable) {
8383
if (__DEV__) {
8484
if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
8585
// if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
86-
warning(
86+
console.error(
8787
'You seem to have overlapping act() calls, this is not supported. ' +
8888
'Be sure to await previous act() calls before making a new one. ',
8989
);
@@ -115,7 +115,7 @@ function act(callback: () => Thenable) {
115115
.then(() => {})
116116
.then(() => {
117117
if (called === false) {
118-
warning(
118+
console.error(
119119
'You called act(async () => ...) without await. ' +
120120
'This could lead to unexpected testing behaviour, interleaving multiple act ' +
121121
'calls and mixing their scopes. You should - await act(async () => ...);',
@@ -163,7 +163,7 @@ function act(callback: () => Thenable) {
163163
} else {
164164
if (__DEV__) {
165165
if (result !== undefined) {
166-
warning(
166+
console.error(
167167
'The callback passed to act(...) function ' +
168168
'must return undefined, or a Promise. You returned %s',
169169
result,
@@ -191,7 +191,7 @@ function act(callback: () => Thenable) {
191191
return {
192192
then(resolve: () => void) {
193193
if (__DEV__) {
194-
warning(
194+
console.error(
195195
'Do not await the result of calling act(...) with sync logic, it is not a Promise.',
196196
);
197197
}

0 commit comments

Comments
 (0)