From 1cd3fec9a1f94714b1279e061afa79ce2b7f3d18 Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Thu, 1 Aug 2024 13:48:46 +0100 Subject: [PATCH] refactor[react-devtools]: remove browserTheme from ConsolePatchSettings --- packages/react-devtools-core/src/cachedSettings.js | 5 ++--- .../src/main/syncSavedPreferences.js | 4 ---- .../react-devtools-shared/src/backend/console.js | 9 +-------- packages/react-devtools-shared/src/backend/types.js | 12 +++--------- .../src/devtools/views/Settings/SettingsContext.js | 2 -- 5 files changed, 6 insertions(+), 26 deletions(-) diff --git a/packages/react-devtools-core/src/cachedSettings.js b/packages/react-devtools-core/src/cachedSettings.js index 18ecd696b3c7c..afe12bfdbc5ad 100644 --- a/packages/react-devtools-core/src/cachedSettings.js +++ b/packages/react-devtools-core/src/cachedSettings.js @@ -9,7 +9,7 @@ import type {ConsolePatchSettings} from 'react-devtools-shared/src/backend/types'; import {writeConsolePatchSettingsToWindow} from 'react-devtools-shared/src/backend/console'; -import {castBool, castBrowserTheme} from 'react-devtools-shared/src/utils'; +import {castBool} from 'react-devtools-shared/src/utils'; // Note: all keys should be optional in this type, because users can use newer // versions of React DevTools with older versions of React Native, and the object @@ -54,14 +54,13 @@ function parseConsolePatchSettings( breakOnConsoleErrors, showInlineWarningsAndErrors, hideConsoleLogsInStrictMode, - browserTheme, } = parsedValue; + return { appendComponentStack: castBool(appendComponentStack) ?? true, breakOnConsoleErrors: castBool(breakOnConsoleErrors) ?? false, showInlineWarningsAndErrors: castBool(showInlineWarningsAndErrors) ?? true, hideConsoleLogsInStrictMode: castBool(hideConsoleLogsInStrictMode) ?? false, - browserTheme: castBrowserTheme(browserTheme) ?? 'dark', }; } diff --git a/packages/react-devtools-extensions/src/main/syncSavedPreferences.js b/packages/react-devtools-extensions/src/main/syncSavedPreferences.js index 6ceed86fcd06d..f22d41eb7c904 100644 --- a/packages/react-devtools-extensions/src/main/syncSavedPreferences.js +++ b/packages/react-devtools-extensions/src/main/syncSavedPreferences.js @@ -7,7 +7,6 @@ import { getShowInlineWarningsAndErrors, getHideConsoleLogsInStrictMode, } from 'react-devtools-shared/src/utils'; -import {getBrowserTheme} from 'react-devtools-extensions/src/utils'; // The renderer interface can't read saved component filters directly, // because they are stored in localStorage within the context of the extension. @@ -28,9 +27,6 @@ function syncSavedPreferences() { )}; window.__REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = ${JSON.stringify( getHideConsoleLogsInStrictMode(), - )}; - window.__REACT_DEVTOOLS_BROWSER_THEME__ = ${JSON.stringify( - getBrowserTheme(), )};`, ); } diff --git a/packages/react-devtools-shared/src/backend/console.js b/packages/react-devtools-shared/src/backend/console.js index e213edef64c40..e511abb5dfee2 100644 --- a/packages/react-devtools-shared/src/backend/console.js +++ b/packages/react-devtools-shared/src/backend/console.js @@ -18,7 +18,7 @@ import { ANSI_STYLE_DIMMING_TEMPLATE, ANSI_STYLE_DIMMING_TEMPLATE_WITH_COMPONENT_STACK, } from 'react-devtools-shared/src/constants'; -import {castBool, castBrowserTheme} from '../utils'; +import {castBool} from '../utils'; const OVERRIDE_CONSOLE_METHODS = ['error', 'trace', 'warn']; @@ -125,7 +125,6 @@ const consoleSettingsRef: ConsolePatchSettings = { breakOnConsoleErrors: false, showInlineWarningsAndErrors: false, hideConsoleLogsInStrictMode: false, - browserTheme: 'dark', }; // Patches console methods to append component stack for the current fiber. @@ -135,7 +134,6 @@ export function patch({ breakOnConsoleErrors, showInlineWarningsAndErrors, hideConsoleLogsInStrictMode, - browserTheme, }: $ReadOnly): void { // Settings may change after we've patched the console. // Using a shared ref allows the patch function to read the latest values. @@ -143,7 +141,6 @@ export function patch({ consoleSettingsRef.breakOnConsoleErrors = breakOnConsoleErrors; consoleSettingsRef.showInlineWarningsAndErrors = showInlineWarningsAndErrors; consoleSettingsRef.hideConsoleLogsInStrictMode = hideConsoleLogsInStrictMode; - consoleSettingsRef.browserTheme = browserTheme; if ( appendComponentStack || @@ -403,15 +400,12 @@ export function patchConsoleUsingWindowValues() { const hideConsoleLogsInStrictMode = castBool(window.__REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__) ?? false; - const browserTheme = - castBrowserTheme(window.__REACT_DEVTOOLS_BROWSER_THEME__) ?? 'dark'; patch({ appendComponentStack, breakOnConsoleErrors, showInlineWarningsAndErrors, hideConsoleLogsInStrictMode, - browserTheme, }); } @@ -429,7 +423,6 @@ export function writeConsolePatchSettingsToWindow( settings.showInlineWarningsAndErrors; window.__REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = settings.hideConsoleLogsInStrictMode; - window.__REACT_DEVTOOLS_BROWSER_THEME__ = settings.browserTheme; } export function installConsoleFunctionsToWindow(): void { diff --git a/packages/react-devtools-shared/src/backend/types.js b/packages/react-devtools-shared/src/backend/types.js index e41135f5f41f4..fa5dcfdb41ec4 100644 --- a/packages/react-devtools-shared/src/backend/types.js +++ b/packages/react-devtools-shared/src/backend/types.js @@ -31,7 +31,6 @@ import type { } from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor'; import type {InitBackend} from 'react-devtools-shared/src/backend'; import type {TimelineDataExport} from 'react-devtools-timeline/src/types'; -import type {BrowserTheme} from 'react-devtools-shared/src/frontend/types'; import type {BackendBridge} from 'react-devtools-shared/src/bridge'; import type {Source} from 'react-devtools-shared/src/shared/types'; import type Agent from './agent'; @@ -522,17 +521,12 @@ export type DevToolsHook = { ... }; -export type ConsolePatchSettings = { - appendComponentStack: boolean, - breakOnConsoleErrors: boolean, - showInlineWarningsAndErrors: boolean, - hideConsoleLogsInStrictMode: boolean, - browserTheme: BrowserTheme, -}; - export type DevToolsHookSettings = { appendComponentStack: boolean, breakOnConsoleErrors: boolean, showInlineWarningsAndErrors: boolean, hideConsoleLogsInStrictMode: boolean, }; + +// Will be removed together with console patching from backend/console.js to hook.js +export type ConsolePatchSettings = DevToolsHookSettings; diff --git a/packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js b/packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js index a6f2c5e8c2a78..33487c2f553d6 100644 --- a/packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js @@ -202,7 +202,6 @@ function SettingsContextController({ breakOnConsoleErrors, showInlineWarningsAndErrors, hideConsoleLogsInStrictMode, - browserTheme, }); }, [ bridge, @@ -210,7 +209,6 @@ function SettingsContextController({ breakOnConsoleErrors, showInlineWarningsAndErrors, hideConsoleLogsInStrictMode, - browserTheme, ]); useEffect(() => {