[flags] remove enableRemoveConsolePatches (#32425)
wait to merge until we sync https://github.com/facebook/react/pull/32376, since that enables it in some testing builds that might break
Ricky committed
Feb 24, 2025 at 10:00 UTC
25677265038b89c1ee3000e0669339ed160d9d75
14 files changed
-279
packages/react-reconciler/src/ReactFiberDevToolsHook.js
-2
@@ -36,7 +36,6 @@ import {
36
log,
37
unstable_setDisableYieldValue,
38
} from './Scheduler';
39
-import {setSuppressWarning} from 'shared/consoleWithStackDev';
39
40
declare const __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
41
@@ -191,7 +190,6 @@ export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
190
// in SchedulerMock. To reduce the noise in strict mode tests,
191
// suppress warnings and disable scheduler yielding during the double render
192
unstable_setDisableYieldValue(newIsStrictMode);
194
- setSuppressWarning(newIsStrictMode);
193
}
194
195
if (injectedHook && typeof injectedHook.setStrictMode === 'function') {
packages/shared/ReactFeatureFlags.js
-2
@@ -267,5 +267,3 @@ export const enableUpdaterTracking = __PROFILE__;
267
268
// Internal only.
269
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
270
-
271
-export const enableRemoveConsolePatches = true;
packages/shared/consoleWithStackDev.js
deleted
-18
@@ -1,18 +0,0 @@
1
-/**
2
- * Copyright (c) Meta Platforms, Inc. and 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
-
8
-// We expect that our Rollup, Jest, and Flow configurations
9
-// always shim this module with the corresponding environment
10
-// (either rn or www).
11
-//
12
-// We should never resolve to this file, but it exists to make
13
-// sure that if we *do* accidentally break the configuration,
14
-// the failure isn't silent.
15
-
16
-export function setSuppressWarning() {
17
- // TODO: Delete this and error when even importing this module.
18
-}
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -34,7 +34,6 @@ export const {
34
35
// These two can be removed
36
export const enableOwnerStacks = true;
37
-export const enableRemoveConsolePatches = true;
37
38
// The rest of the flags are static for better dead code elimination.
39
export const disableClientCache = true;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -81,7 +81,6 @@ export const enableProfilerTimer = __PROFILE__;
81
export const enableProfilerCommitHooks = __PROFILE__;
82
export const enableProfilerNestedUpdatePhase = __PROFILE__;
83
export const enableUpdaterTracking = __PROFILE__;
84
-export const enableRemoveConsolePatches = true;
84
85
// Flow magic to verify the exports of this file match the original version.
86
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -91,7 +91,6 @@ export const disableDefaultPropsExceptForClasses = true;
91
92
export const enableObjectFiber = false;
93
export const enableOwnerStacks = true;
94
-export const enableRemoveConsolePatches = true;
94
95
// Flow magic to verify the exports of this file match the original version.
96
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js
-1
@@ -68,7 +68,6 @@ export const enableHydrationLaneScheduling = true;
68
export const enableYieldingBeforePassive = false;
69
export const enableThrottledScheduling = false;
70
export const enableViewTransition = false;
71
-export const enableRemoveConsolePatches = true;
71
export const enableSwipeTransition = false;
72
export const enableFastAddPropertiesInDiffing = false;
73
export const enableLazyPublicInstanceInFabric = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -83,7 +83,6 @@ export const enableYieldingBeforePassive = false;
83
84
export const enableThrottledScheduling = false;
85
export const enableViewTransition = false;
86
-export const enableRemoveConsolePatches = true;
86
export const enableSwipeTransition = false;
87
export const enableFastAddPropertiesInDiffing = false;
88
export const enableLazyPublicInstanceInFabric = false;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -44,7 +44,6 @@ export const {
44
45
// Can remove these two
46
export const enableOwnerStacks = true;
47
-export const enableRemoveConsolePatches = true;
47
48
export const enableProfilerTimer = __PROFILE__;
49
export const enableProfilerCommitHooks = __PROFILE__;
packages/shared/forks/consoleWithStackDev.rn.js
deleted
-72
@@ -1,72 +0,0 @@
1
-/**
2
- * Copyright (c) Meta Platforms, Inc. and 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
-
8
-import ReactSharedInternals from 'shared/ReactSharedInternals';
9
-import * as dynamicFlagsUntyped from 'ReactNativeInternalFeatureFlags';
10
-const enableRemoveConsolePatches =
11
- dynamicFlagsUntyped && dynamicFlagsUntyped.enableRemoveConsolePatches;
12
-
13
-let suppressWarning = false;
14
-export function setSuppressWarning(newSuppressWarning) {
15
- if (enableRemoveConsolePatches) {
16
- return;
17
- }
18
- if (__DEV__) {
19
- suppressWarning = newSuppressWarning;
20
- }
21
-}
22
-
23
-// In DEV, calls to console.warn and console.error get replaced
24
-// by calls to these methods by a Babel plugin.
25
-//
26
-// In PROD (or in packages without access to React internals),
27
-// they are left as they are instead.
28
-
29
-export function warn(format, ...args) {
30
- if (enableRemoveConsolePatches) {
31
- if (__DEV__) {
32
- console['warn'](format, ...args);
33
- }
34
- } else if (__DEV__) {
35
- if (!suppressWarning) {
36
- printWarning('warn', format, args);
37
- }
38
- }
39
-}
40
-
41
-export function error(format, ...args) {
42
- if (enableRemoveConsolePatches) {
43
- if (__DEV__) {
44
- console['error'](format, ...args);
45
- }
46
- } else if (__DEV__) {
47
- if (!suppressWarning) {
48
- printWarning('error', format, args);
49
- }
50
- }
51
-}
52
-
53
-function printWarning(level, format, args) {
54
- if (enableRemoveConsolePatches) {
55
- return;
56
- }
57
- if (__DEV__) {
58
- if (ReactSharedInternals.getCurrentStack) {
59
- const stack = ReactSharedInternals.getCurrentStack();
60
- if (stack !== '') {
61
- format += '%s';
62
- args = args.concat([stack]);
63
- }
64
- }
65
-
66
- args.unshift(format);
67
- // We intentionally don't use spread (or .apply) directly because it
68
- // breaks IE9: https://github.com/facebook/react/issues/13610
69
- // eslint-disable-next-line react-internal/no-production-logging
70
- Function.prototype.apply.call(console[level], console, args);
71
- }
72
-}
packages/shared/forks/consoleWithStackDev.www.js
deleted
-68
@@ -1,68 +0,0 @@
1
-/**
2
- * Copyright (c) Meta Platforms, Inc. and 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
-
8
-const {enableRemoveConsolePatches} = require('ReactFeatureFlags');
9
-
10
-// This refers to a WWW module.
11
-const warningWWW = require('warning');
12
-
13
-let suppressWarning = false;
14
-export function setSuppressWarning(newSuppressWarning) {
15
- if (enableRemoveConsolePatches) {
16
- return;
17
- }
18
- if (__DEV__) {
19
- suppressWarning = newSuppressWarning;
20
- }
21
-}
22
-
23
-export function warn(format, ...args) {
24
- if (enableRemoveConsolePatches) {
25
- if (__DEV__) {
26
- console['warn'](format, ...args);
27
- }
28
- } else if (__DEV__) {
29
- if (!suppressWarning) {
30
- printWarning('warn', format, args);
31
- }
32
- }
33
-}
34
-
35
-export function error(format, ...args) {
36
- if (enableRemoveConsolePatches) {
37
- if (__DEV__) {
38
- console['error'](format, ...args);
39
- }
40
- } else if (__DEV__) {
41
- if (!suppressWarning) {
42
- printWarning('error', format, args);
43
- }
44
- }
45
-}
46
-
47
-function printWarning(level, format, args) {
48
- if (enableRemoveConsolePatches) {
49
- return;
50
- }
51
- if (__DEV__) {
52
- const React = require('react');
53
- const ReactSharedInternals =
54
- React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
55
- // Defensive in case this is fired before React is initialized.
56
- if (ReactSharedInternals != null && ReactSharedInternals.getCurrentStack) {
57
- const stack = ReactSharedInternals.getCurrentStack();
58
- if (stack !== '') {
59
- format += '%s';
60
- args.push(stack);
61
- }
62
- }
63
- // TODO: don't ignore level and pass it down somewhere too.
64
- args.unshift(format);
65
- args.unshift(false);
66
- warningWWW.apply(null, args);
67
- }
68
-}
scripts/babel/transform-replace-console-calls.js
deleted
-82
@@ -1,82 +0,0 @@
1
-/**
2
- * Copyright (c) Meta Platforms, Inc. and 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
-const helperModuleImports = require('@babel/helper-module-imports');
10
-
11
-module.exports = function replaceConsoleCalls(babel) {
12
- let consoleErrors = new WeakMap();
13
- function getConsoleError(path, file) {
14
- if (!consoleErrors.has(file)) {
15
- consoleErrors.set(
16
- file,
17
- helperModuleImports.addNamed(
18
- path,
19
- 'error',
20
- 'shared/consoleWithStackDev',
21
- {nameHint: 'consoleError'}
22
- )
23
- );
24
- }
25
- return babel.types.cloneDeep(consoleErrors.get(file));
26
- }
27
-
28
- let consoleWarns = new WeakMap();
29
- function getConsoleWarn(path, file) {
30
- if (!consoleWarns.has(file)) {
31
- consoleWarns.set(
32
- file,
33
- helperModuleImports.addNamed(
34
- path,
35
- 'warn',
36
- 'shared/consoleWithStackDev',
37
- {nameHint: 'consoleWarn'}
38
- )
39
- );
40
- }
41
- return babel.types.cloneDeep(consoleWarns.get(file));
42
- }
43
-
44
- return {
45
- visitor: {
46
- CallExpression: function (path, pass) {
47
- if (path.node.callee.type !== 'MemberExpression') {
48
- return;
49
- }
50
- if (path.node.callee.property.type !== 'Identifier') {
51
- // Don't process calls like console['error'](...)
52
- // because they serve as an escape hatch.
53
- return;
54
- }
55
- if (path.get('callee').matchesPattern('console.error')) {
56
- if (this.opts.shouldError) {
57
- throw path.buildCodeFrameError(
58
- "This module has no access to the React object, so it can't " +
59
- 'use console.error() with automatically appended stack. ' +
60
- "As a workaround, you can use console['error'] which won't " +
61
- 'be transformed.'
62
- );
63
- }
64
- const id = getConsoleError(path, pass.file);
65
- path.node.callee = id;
66
- }
67
- if (path.get('callee').matchesPattern('console.warn')) {
68
- if (this.opts.shouldError) {
69
- throw path.buildCodeFrameError(
70
- "This module has no access to the React object, so it can't " +
71
- 'use console.warn() with automatically appended stack. ' +
72
- "As a workaround, you can use console['warn'] which won't " +
73
- 'be transformed.'
74
- );
75
- }
76
- const id = getConsoleWarn(path, pass.file);
77
- path.node.callee = id;
78
- }
79
- },
80
- },
81
- };
82
-};
scripts/rollup/build.js
-17
@@ -145,8 +145,6 @@ function getBabelConfig(
145
isDevelopment,
146
bundle
147
) {
148
- const canAccessReactObject =
149
- packageName === 'react' || externals.indexOf('react') !== -1;
148
let options = {
149
exclude: '/**/node_modules/**',
150
babelrc: false,
@@ -158,21 +156,6 @@ function getBabelConfig(
156
};
157
if (isDevelopment) {
158
options.plugins.push(...babelToES5Plugins);
161
- if (
162
- bundleType === FB_WWW_DEV ||
163
- bundleType === RN_OSS_DEV ||
164
- bundleType === RN_FB_DEV
165
- ) {
166
- options.plugins.push(
167
- // Turn console.error/warn() into a custom wrapper
168
- [
169
- require('../babel/transform-replace-console-calls'),
170
- {
171
- shouldError: !canAccessReactObject,
172
- },
173
- ]
174
- );
175
- }
159
}
160
if (updateBabelOptions) {
161
options = updateBabelOptions(options);
scripts/rollup/forks.js
-12
@@ -209,18 +209,6 @@ const forks = Object.freeze({
209
}
210
},
211
212
- './packages/shared/consoleWithStackDev.js': (bundleType, entry) => {
213
- switch (bundleType) {
214
- case FB_WWW_DEV:
215
- return './packages/shared/forks/consoleWithStackDev.www.js';
216
- case RN_OSS_DEV:
217
- case RN_FB_DEV:
218
- return './packages/shared/forks/consoleWithStackDev.rn.js';
219
- default:
220
- return null;
221
- }
222
- },
223
-
212
'./packages/shared/DefaultPrepareStackTrace.js': (
213
bundleType,
214
entry,