diff --git a/packages/react-devtools-shared/src/backend/console.js b/packages/react-devtools-shared/src/backend/console.js index 13c2249013a3e..0aa0bcdbff8db 100644 --- a/packages/react-devtools-shared/src/backend/console.js +++ b/packages/react-devtools-shared/src/backend/console.js @@ -22,7 +22,6 @@ import { getStackByFiberInDevAndProd, supportsNativeConsoleTasks, } from './DevToolsFiberComponentStack'; -import {consoleManagedByDevToolsDuringStrictMode} from 'react-devtools-feature-flags'; import {castBool, castBrowserTheme} from '../utils'; const OVERRIDE_CONSOLE_METHODS = ['error', 'trace', 'warn']; @@ -302,76 +301,72 @@ let unpatchForStrictModeFn: null | (() => void) = null; // NOTE: KEEP IN SYNC with src/hook.js:patchConsoleForInitialCommitInStrictMode export function patchForStrictMode() { - if (consoleManagedByDevToolsDuringStrictMode) { - const overrideConsoleMethods = [ - 'error', - 'group', - 'groupCollapsed', - 'info', - 'log', - 'trace', - 'warn', - ]; - - if (unpatchForStrictModeFn !== null) { - // Don't patch twice. - return; - } + const overrideConsoleMethods = [ + 'error', + 'group', + 'groupCollapsed', + 'info', + 'log', + 'trace', + 'warn', + ]; + + if (unpatchForStrictModeFn !== null) { + // Don't patch twice. + return; + } - const originalConsoleMethods: {[string]: $FlowFixMe} = {}; + const originalConsoleMethods: {[string]: $FlowFixMe} = {}; - unpatchForStrictModeFn = () => { - for (const method in originalConsoleMethods) { - try { - targetConsole[method] = originalConsoleMethods[method]; - } catch (error) {} - } - }; - - overrideConsoleMethods.forEach(method => { + unpatchForStrictModeFn = () => { + for (const method in originalConsoleMethods) { try { - const originalMethod = (originalConsoleMethods[method] = targetConsole[ - method - ].__REACT_DEVTOOLS_STRICT_MODE_ORIGINAL_METHOD__ - ? targetConsole[method].__REACT_DEVTOOLS_STRICT_MODE_ORIGINAL_METHOD__ - : targetConsole[method]); + targetConsole[method] = originalConsoleMethods[method]; + } catch (error) {} + } + }; - // $FlowFixMe[missing-local-annot] - const overrideMethod = (...args) => { - if (!consoleSettingsRef.hideConsoleLogsInStrictMode) { - // Dim the text color of the double logs if we're not - // hiding them. - if (isNode) { - originalMethod(DIMMED_NODE_CONSOLE_COLOR, format(...args)); + overrideConsoleMethods.forEach(method => { + try { + const originalMethod = (originalConsoleMethods[method] = targetConsole[ + method + ].__REACT_DEVTOOLS_STRICT_MODE_ORIGINAL_METHOD__ + ? targetConsole[method].__REACT_DEVTOOLS_STRICT_MODE_ORIGINAL_METHOD__ + : targetConsole[method]); + + // $FlowFixMe[missing-local-annot] + const overrideMethod = (...args) => { + if (!consoleSettingsRef.hideConsoleLogsInStrictMode) { + // Dim the text color of the double logs if we're not + // hiding them. + if (isNode) { + originalMethod(DIMMED_NODE_CONSOLE_COLOR, format(...args)); + } else { + const color = getConsoleColor(method); + if (color) { + originalMethod(...formatWithStyles(args, `color: ${color}`)); } else { - const color = getConsoleColor(method); - if (color) { - originalMethod(...formatWithStyles(args, `color: ${color}`)); - } else { - throw Error('Console color is not defined'); - } + throw Error('Console color is not defined'); } } - }; + } + }; - overrideMethod.__REACT_DEVTOOLS_STRICT_MODE_ORIGINAL_METHOD__ = - originalMethod; - originalMethod.__REACT_DEVTOOLS_STRICT_MODE_OVERRIDE_METHOD__ = - overrideMethod; + overrideMethod.__REACT_DEVTOOLS_STRICT_MODE_ORIGINAL_METHOD__ = + originalMethod; + originalMethod.__REACT_DEVTOOLS_STRICT_MODE_OVERRIDE_METHOD__ = + overrideMethod; - targetConsole[method] = overrideMethod; - } catch (error) {} - }); - } + targetConsole[method] = overrideMethod; + } catch (error) {} + }); } // NOTE: KEEP IN SYNC with src/hook.js:unpatchConsoleForInitialCommitInStrictMode export function unpatchForStrictMode(): void { - if (consoleManagedByDevToolsDuringStrictMode) { - if (unpatchForStrictModeFn !== null) { - unpatchForStrictModeFn(); - unpatchForStrictModeFn = null; - } + if (unpatchForStrictModeFn !== null) { + unpatchForStrictModeFn(); + unpatchForStrictModeFn = null; } } diff --git a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-fb.js b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-fb.js index 9c29e361fae91..47e15953c9780 100644 --- a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-fb.js +++ b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-fb.js @@ -13,7 +13,6 @@ * It should always be imported from "react-devtools-feature-flags". ************************************************************************/ -export const consoleManagedByDevToolsDuringStrictMode = false; export const enableLogger = true; export const enableStyleXFeatures = true; export const isInternalFacebookBuild = true; diff --git a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-oss.js b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-oss.js index 060e5e808ede2..e7ec62243adef 100644 --- a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-oss.js +++ b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-oss.js @@ -13,7 +13,6 @@ * It should always be imported from "react-devtools-feature-flags". ************************************************************************/ -export const consoleManagedByDevToolsDuringStrictMode = false; export const enableLogger = false; export const enableStyleXFeatures = false; export const isInternalFacebookBuild = false; diff --git a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.default.js b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.default.js index 15b764f8d352b..bba2c8fcbfb05 100644 --- a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.default.js +++ b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.default.js @@ -13,7 +13,6 @@ * It should always be imported from "react-devtools-feature-flags". ************************************************************************/ -export const consoleManagedByDevToolsDuringStrictMode = true; export const enableLogger = false; export const enableStyleXFeatures = false; export const isInternalFacebookBuild = false; diff --git a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-fb.js b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-fb.js index b25db375eff29..55ea045715013 100644 --- a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-fb.js +++ b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-fb.js @@ -13,7 +13,6 @@ * It should always be imported from "react-devtools-feature-flags". ************************************************************************/ -export const consoleManagedByDevToolsDuringStrictMode = true; export const enableLogger = true; export const enableStyleXFeatures = true; export const isInternalFacebookBuild = true; diff --git a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-oss.js b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-oss.js index 144ddb301f848..75c8f149b3814 100644 --- a/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-oss.js +++ b/packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-oss.js @@ -13,7 +13,6 @@ * It should always be imported from "react-devtools-feature-flags". ************************************************************************/ -export const consoleManagedByDevToolsDuringStrictMode = true; export const enableLogger = false; export const enableStyleXFeatures = false; export const isInternalFacebookBuild = false;