chore: remove settings manager from react-devtools-core (#30986)

Stacked on https://github.com/facebook/react/pull/30636. See [this
commit](20cec76c44).

This has been only used for React Native and will be replaced by another
approach (initialization via `installHook` call) in the next PR.
This commit is contained in:
Ruslan Lesiutin
2024-09-18 18:30:32 +01:00
committed by GitHub
parent f37c7bc653
commit f2c57a31e9
4 changed files with 0 additions and 148 deletions

View File

@@ -14,11 +14,6 @@ import {initBackend} from 'react-devtools-shared/src/backend';
import {__DEBUG__} from 'react-devtools-shared/src/constants';
import setupNativeStyleEditor from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';
import {getDefaultComponentFilters} from 'react-devtools-shared/src/utils';
import {
initializeUsingCachedSettings,
cacheConsolePatchSettings,
type DevToolsSettingsManager,
} from './cachedSettings';
import type {BackendBridge} from 'react-devtools-shared/src/bridge';
import type {
@@ -37,7 +32,6 @@ type ConnectOptions = {
retryConnectionDelay?: number,
isAppActive?: () => boolean,
websocket?: ?WebSocket,
devToolsSettingsManager: ?DevToolsSettingsManager,
};
installHook(window);
@@ -72,7 +66,6 @@ export function connectToDevTools(options: ?ConnectOptions) {
resolveRNStyle = (null: $FlowFixMe),
retryConnectionDelay = 2000,
isAppActive = () => true,
devToolsSettingsManager,
} = options || {};
const protocol = useHttps ? 'wss' : 'ws';
@@ -88,16 +81,6 @@ export function connectToDevTools(options: ?ConnectOptions) {
}
}
if (devToolsSettingsManager != null) {
try {
initializeUsingCachedSettings(devToolsSettingsManager);
} catch (e) {
// If we call a method on devToolsSettingsManager that throws, or if
// is invalid data read out, don't throw and don't interrupt initialization
console.error(e);
}
}
if (!isAppActive()) {
// If the app is in background, maybe retry later.
// Don't actually attempt to connect until we're in foreground.
@@ -161,15 +144,6 @@ export function connectToDevTools(options: ?ConnectOptions) {
},
);
if (devToolsSettingsManager != null && bridge != null) {
bridge.addListener('updateHookSettings', consolePatchSettings =>
cacheConsolePatchSettings(
devToolsSettingsManager,
consolePatchSettings,
),
);
}
// The renderer interface doesn't read saved component filters directly,
// because they are generally stored in localStorage within the context of the extension.
// Because of this it relies on the extension to pass filters.
@@ -314,7 +288,6 @@ type ConnectWithCustomMessagingOptions = {
onSubscribe: (cb: Function) => void,
onUnsubscribe: (cb: Function) => void,
onMessage: (event: string, payload: any) => void,
settingsManager: ?DevToolsSettingsManager,
nativeStyleEditorValidAttributes?: $ReadOnlyArray<string>,
resolveRNStyle?: ResolveNativeStyle,
};
@@ -323,7 +296,6 @@ export function connectWithCustomMessagingProtocol({
onSubscribe,
onUnsubscribe,
onMessage,
settingsManager,
nativeStyleEditorValidAttributes,
resolveRNStyle,
}: ConnectWithCustomMessagingOptions): Function {
@@ -332,16 +304,6 @@ export function connectWithCustomMessagingProtocol({
return;
}
if (settingsManager != null) {
try {
initializeUsingCachedSettings(settingsManager);
} catch (e) {
// If we call a method on devToolsSettingsManager that throws, or if
// is invalid data read out, don't throw and don't interrupt initialization
console.error(e);
}
}
const wall: Wall = {
listen(fn: Function) {
onSubscribe(fn);
@@ -367,12 +329,6 @@ export function connectWithCustomMessagingProtocol({
},
);
if (settingsManager != null) {
bridge.addListener('updateHookSettings', consolePatchSettings =>
cacheConsolePatchSettings(settingsManager, consolePatchSettings),
);
}
if (window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ == null) {
bridge.send('overrideComponentFilters', savedComponentFilters);
}

View File

@@ -1,75 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {ConsolePatchSettings} from 'react-devtools-shared/src/backend/types';
import {writeConsolePatchSettingsToWindow} from 'react-devtools-shared/src/backend/console';
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
// provided by React Native may not include all of this type's fields.
export type DevToolsSettingsManager = {
getConsolePatchSettings: ?() => string,
setConsolePatchSettings: ?(key: string) => void,
};
export function initializeUsingCachedSettings(
devToolsSettingsManager: DevToolsSettingsManager,
) {
initializeConsolePatchSettings(devToolsSettingsManager);
}
function initializeConsolePatchSettings(
devToolsSettingsManager: DevToolsSettingsManager,
) {
if (devToolsSettingsManager.getConsolePatchSettings == null) {
return;
}
const consolePatchSettingsString =
devToolsSettingsManager.getConsolePatchSettings();
if (consolePatchSettingsString == null) {
return;
}
const parsedConsolePatchSettings = parseConsolePatchSettings(
consolePatchSettingsString,
);
if (parsedConsolePatchSettings == null) {
return;
}
writeConsolePatchSettingsToWindow(parsedConsolePatchSettings);
}
function parseConsolePatchSettings(
consolePatchSettingsString: string,
): ?ConsolePatchSettings {
const parsedValue = JSON.parse(consolePatchSettingsString ?? '{}');
const {
appendComponentStack,
breakOnConsoleErrors,
showInlineWarningsAndErrors,
hideConsoleLogsInStrictMode,
} = parsedValue;
return {
appendComponentStack: castBool(appendComponentStack) ?? true,
breakOnConsoleErrors: castBool(breakOnConsoleErrors) ?? false,
showInlineWarningsAndErrors: castBool(showInlineWarningsAndErrors) ?? true,
hideConsoleLogsInStrictMode: castBool(hideConsoleLogsInStrictMode) ?? false,
};
}
export function cacheConsolePatchSettings(
devToolsSettingsManager: DevToolsSettingsManager,
value: $ReadOnly<ConsolePatchSettings>,
): void {
if (devToolsSettingsManager.setConsolePatchSettings == null) {
return;
}
devToolsSettingsManager.setConsolePatchSettings(JSON.stringify(value));
}

View File

@@ -1,26 +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.
*
* @flow
*/
import type {ConsolePatchSettings} from './types';
// After receiving cached console patch settings from React Native, we set them on window.
// When the console is initially patched (in renderer.js and hook.js), these values are read.
// The browser extension (etc.) sets these values on window, but through another method.
export function writeConsolePatchSettingsToWindow(
settings: ConsolePatchSettings,
): void {
window.__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ =
settings.appendComponentStack;
window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ =
settings.breakOnConsoleErrors;
window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ =
settings.showInlineWarningsAndErrors;
window.__REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ =
settings.hideConsoleLogsInStrictMode;
}

View File

@@ -534,6 +534,3 @@ export type DevToolsHookSettings = {
showInlineWarningsAndErrors: boolean,
hideConsoleLogsInStrictMode: boolean,
};
// Will be removed together with console patching from backend/console.js to hook.js
export type ConsolePatchSettings = DevToolsHookSettings;