@samitouri / QOS-React-1 / commits / f2c57a31e9

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

Stacked on https://github.com/facebook/react/pull/30636. See [this commit](https://github.com/facebook/react/pull/30986/commits/20cec76c44f77e74b3a85225fecab5a431cd986f). This has been only used for React Native and will be replaced by another approach (initialization via `installHook` call) in the next PR.

Ruslan Lesiutin committed Sep 18, 2024 at 18:30 UTC f2c57a31e9953b3889c56f68e129e67afca15d0e
4 files changed -148
packages/react-devtools-core/src/backend.js
-44
@@ -14,11 +14,6 @@ import {initBackend} from 'react-devtools-shared/src/backend';
14 import {__DEBUG__} from 'react-devtools-shared/src/constants';
15 import setupNativeStyleEditor from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';
16 import {getDefaultComponentFilters} from 'react-devtools-shared/src/utils';
17 -import {
18 - initializeUsingCachedSettings,
19 - cacheConsolePatchSettings,
20 - type DevToolsSettingsManager,
21 -} from './cachedSettings';
17
18 import type {BackendBridge} from 'react-devtools-shared/src/bridge';
19 import type {
@@ -37,7 +32,6 @@ type ConnectOptions = {
32 retryConnectionDelay?: number,
33 isAppActive?: () => boolean,
34 websocket?: ?WebSocket,
40 - devToolsSettingsManager: ?DevToolsSettingsManager,
35 };
36
37 installHook(window);
@@ -72,7 +66,6 @@ export function connectToDevTools(options: ?ConnectOptions) {
66 resolveRNStyle = (null: $FlowFixMe),
67 retryConnectionDelay = 2000,
68 isAppActive = () => true,
75 - devToolsSettingsManager,
69 } = options || {};
70
71 const protocol = useHttps ? 'wss' : 'ws';
@@ -88,16 +81,6 @@ export function connectToDevTools(options: ?ConnectOptions) {
81 }
82 }
83
91 - if (devToolsSettingsManager != null) {
92 - try {
93 - initializeUsingCachedSettings(devToolsSettingsManager);
94 - } catch (e) {
95 - // If we call a method on devToolsSettingsManager that throws, or if
96 - // is invalid data read out, don't throw and don't interrupt initialization
97 - console.error(e);
98 - }
99 - }
100 -
84 if (!isAppActive()) {
85 // If the app is in background, maybe retry later.
86 // Don't actually attempt to connect until we're in foreground.
@@ -161,15 +144,6 @@ export function connectToDevTools(options: ?ConnectOptions) {
144 },
145 );
146
164 - if (devToolsSettingsManager != null && bridge != null) {
165 - bridge.addListener('updateHookSettings', consolePatchSettings =>
166 - cacheConsolePatchSettings(
167 - devToolsSettingsManager,
168 - consolePatchSettings,
169 - ),
170 - );
171 - }
172 -
147 // The renderer interface doesn't read saved component filters directly,
148 // because they are generally stored in localStorage within the context of the extension.
149 // Because of this it relies on the extension to pass filters.
@@ -314,7 +288,6 @@ type ConnectWithCustomMessagingOptions = {
288 onSubscribe: (cb: Function) => void,
289 onUnsubscribe: (cb: Function) => void,
290 onMessage: (event: string, payload: any) => void,
317 - settingsManager: ?DevToolsSettingsManager,
291 nativeStyleEditorValidAttributes?: $ReadOnlyArray<string>,
292 resolveRNStyle?: ResolveNativeStyle,
293 };
@@ -323,7 +296,6 @@ export function connectWithCustomMessagingProtocol({
296 onSubscribe,
297 onUnsubscribe,
298 onMessage,
326 - settingsManager,
299 nativeStyleEditorValidAttributes,
300 resolveRNStyle,
301 }: ConnectWithCustomMessagingOptions): Function {
@@ -332,16 +304,6 @@ export function connectWithCustomMessagingProtocol({
304 return;
305 }
306
335 - if (settingsManager != null) {
336 - try {
337 - initializeUsingCachedSettings(settingsManager);
338 - } catch (e) {
339 - // If we call a method on devToolsSettingsManager that throws, or if
340 - // is invalid data read out, don't throw and don't interrupt initialization
341 - console.error(e);
342 - }
343 - }
344 -
307 const wall: Wall = {
308 listen(fn: Function) {
309 onSubscribe(fn);
@@ -367,12 +329,6 @@ export function connectWithCustomMessagingProtocol({
329 },
330 );
331
370 - if (settingsManager != null) {
371 - bridge.addListener('updateHookSettings', consolePatchSettings =>
372 - cacheConsolePatchSettings(settingsManager, consolePatchSettings),
373 - );
374 - }
375 -
332 if (window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ == null) {
333 bridge.send('overrideComponentFilters', savedComponentFilters);
334 }
packages/react-devtools-core/src/cachedSettings.js deleted
-75
@@ -1,75 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {ConsolePatchSettings} from 'react-devtools-shared/src/backend/types';
11 -import {writeConsolePatchSettingsToWindow} from 'react-devtools-shared/src/backend/console';
12 -import {castBool} from 'react-devtools-shared/src/utils';
13 -
14 -// Note: all keys should be optional in this type, because users can use newer
15 -// versions of React DevTools with older versions of React Native, and the object
16 -// provided by React Native may not include all of this type's fields.
17 -export type DevToolsSettingsManager = {
18 - getConsolePatchSettings: ?() => string,
19 - setConsolePatchSettings: ?(key: string) => void,
20 -};
21 -
22 -export function initializeUsingCachedSettings(
23 - devToolsSettingsManager: DevToolsSettingsManager,
24 -) {
25 - initializeConsolePatchSettings(devToolsSettingsManager);
26 -}
27 -
28 -function initializeConsolePatchSettings(
29 - devToolsSettingsManager: DevToolsSettingsManager,
30 -) {
31 - if (devToolsSettingsManager.getConsolePatchSettings == null) {
32 - return;
33 - }
34 - const consolePatchSettingsString =
35 - devToolsSettingsManager.getConsolePatchSettings();
36 - if (consolePatchSettingsString == null) {
37 - return;
38 - }
39 - const parsedConsolePatchSettings = parseConsolePatchSettings(
40 - consolePatchSettingsString,
41 - );
42 - if (parsedConsolePatchSettings == null) {
43 - return;
44 - }
45 - writeConsolePatchSettingsToWindow(parsedConsolePatchSettings);
46 -}
47 -
48 -function parseConsolePatchSettings(
49 - consolePatchSettingsString: string,
50 -): ?ConsolePatchSettings {
51 - const parsedValue = JSON.parse(consolePatchSettingsString ?? '{}');
52 - const {
53 - appendComponentStack,
54 - breakOnConsoleErrors,
55 - showInlineWarningsAndErrors,
56 - hideConsoleLogsInStrictMode,
57 - } = parsedValue;
58 -
59 - return {
60 - appendComponentStack: castBool(appendComponentStack) ?? true,
61 - breakOnConsoleErrors: castBool(breakOnConsoleErrors) ?? false,
62 - showInlineWarningsAndErrors: castBool(showInlineWarningsAndErrors) ?? true,
63 - hideConsoleLogsInStrictMode: castBool(hideConsoleLogsInStrictMode) ?? false,
64 - };
65 -}
66 -
67 -export function cacheConsolePatchSettings(
68 - devToolsSettingsManager: DevToolsSettingsManager,
69 - value: $ReadOnly<ConsolePatchSettings>,
70 -): void {
71 - if (devToolsSettingsManager.setConsolePatchSettings == null) {
72 - return;
73 - }
74 - devToolsSettingsManager.setConsolePatchSettings(JSON.stringify(value));
75 -}
packages/react-devtools-shared/src/backend/console.js deleted
-26
@@ -1,26 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {ConsolePatchSettings} from './types';
11 -
12 -// After receiving cached console patch settings from React Native, we set them on window.
13 -// When the console is initially patched (in renderer.js and hook.js), these values are read.
14 -// The browser extension (etc.) sets these values on window, but through another method.
15 -export function writeConsolePatchSettingsToWindow(
16 - settings: ConsolePatchSettings,
17 -): void {
18 - window.__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ =
19 - settings.appendComponentStack;
20 - window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ =
21 - settings.breakOnConsoleErrors;
22 - window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ =
23 - settings.showInlineWarningsAndErrors;
24 - window.__REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ =
25 - settings.hideConsoleLogsInStrictMode;
26 -}
packages/react-devtools-shared/src/backend/types.js
-3
@@ -534,6 +534,3 @@ export type DevToolsHookSettings = {
534 showInlineWarningsAndErrors: boolean,
535 hideConsoleLogsInStrictMode: boolean,
536 };
537 -
538 -// Will be removed together with console patching from backend/console.js to hook.js
539 -export type ConsolePatchSettings = DevToolsHookSettings;