diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.js index 98bad19a8e296..dc357f1ac1aad 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.js @@ -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') { diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index f1f1a09373664..1a2c260b5ba2d 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -267,5 +267,3 @@ export const enableUpdaterTracking = __PROFILE__; // Internal only. export const enableDO_NOT_USE_disableStrictPassiveEffect = false; - -export const enableRemoveConsolePatches = true; diff --git a/packages/shared/consoleWithStackDev.js b/packages/shared/consoleWithStackDev.js deleted file mode 100644 index 072f11859985f..0000000000000 --- a/packages/shared/consoleWithStackDev.js +++ /dev/null @@ -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. -} diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 5c3015563d51c..8d72f54fc94cd 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -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; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index f767b3427b25f..ea29191274af1 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 181e504ef7e1b..821a577026c32 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js index dcca098b21539..c239f61b78b6b 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js @@ -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; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 31ac32b253dd4..443bed04b790f 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -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; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index f3fdc1e4f489e..de1f2f316bb53 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -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__; diff --git a/packages/shared/forks/consoleWithStackDev.rn.js b/packages/shared/forks/consoleWithStackDev.rn.js deleted file mode 100644 index ec02866061c47..0000000000000 --- a/packages/shared/forks/consoleWithStackDev.rn.js +++ /dev/null @@ -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); - } -} diff --git a/packages/shared/forks/consoleWithStackDev.www.js b/packages/shared/forks/consoleWithStackDev.www.js deleted file mode 100644 index 84c5d186e4a8e..0000000000000 --- a/packages/shared/forks/consoleWithStackDev.www.js +++ /dev/null @@ -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); - } -} diff --git a/scripts/babel/transform-replace-console-calls.js b/scripts/babel/transform-replace-console-calls.js deleted file mode 100644 index 387f88a5f948e..0000000000000 --- a/scripts/babel/transform-replace-console-calls.js +++ /dev/null @@ -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; - } - }, - }, - }; -}; diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 53b308d16a2d8..874b5b139f37c 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -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); diff --git a/scripts/rollup/forks.js b/scripts/rollup/forks.js index 5460304366253..33c7c96abbc06 100644 --- a/scripts/rollup/forks.js +++ b/scripts/rollup/forks.js @@ -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,