[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
This commit is contained in:
Ricky
2025-02-24 10:00:22 -05:00
committed by GitHub
parent 9dd378ff12
commit 2567726503
14 changed files with 0 additions and 279 deletions

View File

@@ -36,7 +36,6 @@ import {
log,
unstable_setDisableYieldValue,
} from './Scheduler';
import {setSuppressWarning} from 'shared/consoleWithStackDev';
declare const __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
@@ -191,7 +190,6 @@ export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
// in SchedulerMock. To reduce the noise in strict mode tests,
// suppress warnings and disable scheduler yielding during the double render
unstable_setDisableYieldValue(newIsStrictMode);
setSuppressWarning(newIsStrictMode);
}
if (injectedHook && typeof injectedHook.setStrictMode === 'function') {

View File

@@ -267,5 +267,3 @@ export const enableUpdaterTracking = __PROFILE__;
// Internal only.
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
export const enableRemoveConsolePatches = true;

View File

@@ -1,18 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// We expect that our Rollup, Jest, and Flow configurations
// always shim this module with the corresponding environment
// (either rn or www).
//
// We should never resolve to this file, but it exists to make
// sure that if we *do* accidentally break the configuration,
// the failure isn't silent.
export function setSuppressWarning() {
// TODO: Delete this and error when even importing this module.
}

View File

@@ -34,7 +34,6 @@ export const {
// These two can be removed
export const enableOwnerStacks = true;
export const enableRemoveConsolePatches = true;
// The rest of the flags are static for better dead code elimination.
export const disableClientCache = true;

View File

@@ -81,7 +81,6 @@ export const enableProfilerTimer = __PROFILE__;
export const enableProfilerCommitHooks = __PROFILE__;
export const enableProfilerNestedUpdatePhase = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;
export const enableRemoveConsolePatches = true;
// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

View File

@@ -91,7 +91,6 @@ export const disableDefaultPropsExceptForClasses = true;
export const enableObjectFiber = false;
export const enableOwnerStacks = true;
export const enableRemoveConsolePatches = true;
// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

View File

@@ -68,7 +68,6 @@ export const enableHydrationLaneScheduling = true;
export const enableYieldingBeforePassive = false;
export const enableThrottledScheduling = false;
export const enableViewTransition = false;
export const enableRemoveConsolePatches = true;
export const enableSwipeTransition = false;
export const enableFastAddPropertiesInDiffing = false;
export const enableLazyPublicInstanceInFabric = false;

View File

@@ -83,7 +83,6 @@ export const enableYieldingBeforePassive = false;
export const enableThrottledScheduling = false;
export const enableViewTransition = false;
export const enableRemoveConsolePatches = true;
export const enableSwipeTransition = false;
export const enableFastAddPropertiesInDiffing = false;
export const enableLazyPublicInstanceInFabric = false;

View File

@@ -44,7 +44,6 @@ export const {
// Can remove these two
export const enableOwnerStacks = true;
export const enableRemoveConsolePatches = true;
export const enableProfilerTimer = __PROFILE__;
export const enableProfilerCommitHooks = __PROFILE__;

View File

@@ -1,72 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import ReactSharedInternals from 'shared/ReactSharedInternals';
import * as dynamicFlagsUntyped from 'ReactNativeInternalFeatureFlags';
const enableRemoveConsolePatches =
dynamicFlagsUntyped && dynamicFlagsUntyped.enableRemoveConsolePatches;
let suppressWarning = false;
export function setSuppressWarning(newSuppressWarning) {
if (enableRemoveConsolePatches) {
return;
}
if (__DEV__) {
suppressWarning = newSuppressWarning;
}
}
// In DEV, calls to console.warn and console.error get replaced
// by calls to these methods by a Babel plugin.
//
// In PROD (or in packages without access to React internals),
// they are left as they are instead.
export function warn(format, ...args) {
if (enableRemoveConsolePatches) {
if (__DEV__) {
console['warn'](format, ...args);
}
} else if (__DEV__) {
if (!suppressWarning) {
printWarning('warn', format, args);
}
}
}
export function error(format, ...args) {
if (enableRemoveConsolePatches) {
if (__DEV__) {
console['error'](format, ...args);
}
} else if (__DEV__) {
if (!suppressWarning) {
printWarning('error', format, args);
}
}
}
function printWarning(level, format, args) {
if (enableRemoveConsolePatches) {
return;
}
if (__DEV__) {
if (ReactSharedInternals.getCurrentStack) {
const stack = ReactSharedInternals.getCurrentStack();
if (stack !== '') {
format += '%s';
args = args.concat([stack]);
}
}
args.unshift(format);
// We intentionally don't use spread (or .apply) directly because it
// breaks IE9: https://github.com/facebook/react/issues/13610
// eslint-disable-next-line react-internal/no-production-logging
Function.prototype.apply.call(console[level], console, args);
}
}

View File

@@ -1,68 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const {enableRemoveConsolePatches} = require('ReactFeatureFlags');
// This refers to a WWW module.
const warningWWW = require('warning');
let suppressWarning = false;
export function setSuppressWarning(newSuppressWarning) {
if (enableRemoveConsolePatches) {
return;
}
if (__DEV__) {
suppressWarning = newSuppressWarning;
}
}
export function warn(format, ...args) {
if (enableRemoveConsolePatches) {
if (__DEV__) {
console['warn'](format, ...args);
}
} else if (__DEV__) {
if (!suppressWarning) {
printWarning('warn', format, args);
}
}
}
export function error(format, ...args) {
if (enableRemoveConsolePatches) {
if (__DEV__) {
console['error'](format, ...args);
}
} else if (__DEV__) {
if (!suppressWarning) {
printWarning('error', format, args);
}
}
}
function printWarning(level, format, args) {
if (enableRemoveConsolePatches) {
return;
}
if (__DEV__) {
const React = require('react');
const ReactSharedInternals =
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
// Defensive in case this is fired before React is initialized.
if (ReactSharedInternals != null && ReactSharedInternals.getCurrentStack) {
const stack = ReactSharedInternals.getCurrentStack();
if (stack !== '') {
format += '%s';
args.push(stack);
}
}
// TODO: don't ignore level and pass it down somewhere too.
args.unshift(format);
args.unshift(false);
warningWWW.apply(null, args);
}
}

View File

@@ -1,82 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const helperModuleImports = require('@babel/helper-module-imports');
module.exports = function replaceConsoleCalls(babel) {
let consoleErrors = new WeakMap();
function getConsoleError(path, file) {
if (!consoleErrors.has(file)) {
consoleErrors.set(
file,
helperModuleImports.addNamed(
path,
'error',
'shared/consoleWithStackDev',
{nameHint: 'consoleError'}
)
);
}
return babel.types.cloneDeep(consoleErrors.get(file));
}
let consoleWarns = new WeakMap();
function getConsoleWarn(path, file) {
if (!consoleWarns.has(file)) {
consoleWarns.set(
file,
helperModuleImports.addNamed(
path,
'warn',
'shared/consoleWithStackDev',
{nameHint: 'consoleWarn'}
)
);
}
return babel.types.cloneDeep(consoleWarns.get(file));
}
return {
visitor: {
CallExpression: function (path, pass) {
if (path.node.callee.type !== 'MemberExpression') {
return;
}
if (path.node.callee.property.type !== 'Identifier') {
// Don't process calls like console['error'](...)
// because they serve as an escape hatch.
return;
}
if (path.get('callee').matchesPattern('console.error')) {
if (this.opts.shouldError) {
throw path.buildCodeFrameError(
"This module has no access to the React object, so it can't " +
'use console.error() with automatically appended stack. ' +
"As a workaround, you can use console['error'] which won't " +
'be transformed.'
);
}
const id = getConsoleError(path, pass.file);
path.node.callee = id;
}
if (path.get('callee').matchesPattern('console.warn')) {
if (this.opts.shouldError) {
throw path.buildCodeFrameError(
"This module has no access to the React object, so it can't " +
'use console.warn() with automatically appended stack. ' +
"As a workaround, you can use console['warn'] which won't " +
'be transformed.'
);
}
const id = getConsoleWarn(path, pass.file);
path.node.callee = id;
}
},
},
};
};

View File

@@ -145,8 +145,6 @@ function getBabelConfig(
isDevelopment,
bundle
) {
const canAccessReactObject =
packageName === 'react' || externals.indexOf('react') !== -1;
let options = {
exclude: '/**/node_modules/**',
babelrc: false,
@@ -158,21 +156,6 @@ function getBabelConfig(
};
if (isDevelopment) {
options.plugins.push(...babelToES5Plugins);
if (
bundleType === FB_WWW_DEV ||
bundleType === RN_OSS_DEV ||
bundleType === RN_FB_DEV
) {
options.plugins.push(
// Turn console.error/warn() into a custom wrapper
[
require('../babel/transform-replace-console-calls'),
{
shouldError: !canAccessReactObject,
},
]
);
}
}
if (updateBabelOptions) {
options = updateBabelOptions(options);

View File

@@ -209,18 +209,6 @@ const forks = Object.freeze({
}
},
'./packages/shared/consoleWithStackDev.js': (bundleType, entry) => {
switch (bundleType) {
case FB_WWW_DEV:
return './packages/shared/forks/consoleWithStackDev.www.js';
case RN_OSS_DEV:
case RN_FB_DEV:
return './packages/shared/forks/consoleWithStackDev.rn.js';
default:
return null;
}
},
'./packages/shared/DefaultPrepareStackTrace.js': (
bundleType,
entry,