Skip to content

Commit

Permalink
refactor[react-devtools]: remove browserTheme from ConsolePatchSettin…
Browse files Browse the repository at this point in the history
…gs (#30566)

Stacked on #30564.

We are no longer using browser theme in our console patching, this was
removed in unification of console patching for strict mode, we started
using ansi escape symbols and forking based on browser theme is no
longer required - #29869

The real browser theme initialization for frontend is happening at the
other place and is not affected:

https://github.com/facebook/react/blob/40be968257a7a10a267210670103f20dd0429ef3/packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js#L117-L120
  • Loading branch information
hoxyq authored Sep 18, 2024
1 parent 5e83d9a commit b521ef8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 26 deletions.
5 changes: 2 additions & 3 deletions packages/react-devtools-core/src/cachedSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
)};`,
);
}
Expand Down
9 changes: 1 addition & 8 deletions packages/react-devtools-shared/src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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'];

Expand Down Expand Up @@ -124,7 +124,6 @@ const consoleSettingsRef: ConsolePatchSettings = {
breakOnConsoleErrors: false,
showInlineWarningsAndErrors: false,
hideConsoleLogsInStrictMode: false,
browserTheme: 'dark',
};

// Patches console methods to append component stack for the current fiber.
Expand All @@ -134,15 +133,13 @@ export function patch({
breakOnConsoleErrors,
showInlineWarningsAndErrors,
hideConsoleLogsInStrictMode,
browserTheme,
}: $ReadOnly<ConsolePatchSettings>): void {
// Settings may change after we've patched the console.
// Using a shared ref allows the patch function to read the latest values.
consoleSettingsRef.appendComponentStack = appendComponentStack;
consoleSettingsRef.breakOnConsoleErrors = breakOnConsoleErrors;
consoleSettingsRef.showInlineWarningsAndErrors = showInlineWarningsAndErrors;
consoleSettingsRef.hideConsoleLogsInStrictMode = hideConsoleLogsInStrictMode;
consoleSettingsRef.browserTheme = browserTheme;

if (
appendComponentStack ||
Expand Down Expand Up @@ -412,15 +409,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,
});
}

Expand All @@ -438,7 +432,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 {
Expand Down
12 changes: 3 additions & 9 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -531,17 +530,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;
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,13 @@ function SettingsContextController({
breakOnConsoleErrors,
showInlineWarningsAndErrors,
hideConsoleLogsInStrictMode,
browserTheme,
});
}, [
bridge,
appendComponentStack,
breakOnConsoleErrors,
showInlineWarningsAndErrors,
hideConsoleLogsInStrictMode,
browserTheme,
]);

useEffect(() => {
Expand Down

0 comments on commit b521ef8

Please sign in to comment.