Files
react/packages/react-devtools-fusebox/src/frontend.js
T
Ruslan Lesiutin 7625f0d501 feat[devtools-fusebox]: support theme option (#28832)
Support propagating theme from Chrome DevTools frontend, the field is
optional.

Next step, which is out of scope of this project and general improvement
for React DevTools: teach RDT to listen to theme changes and if the
theme preference is set to `auto` in settings, update the theme
accordingly with the browser devtools.
2024-04-12 17:26:37 +01:00

68 lines
1.6 KiB
JavaScript

/**
* 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 * as React from 'react';
import {createRoot} from 'react-dom/client';
import Bridge from 'react-devtools-shared/src/bridge';
import Store from 'react-devtools-shared/src/devtools/store';
import DevTools from 'react-devtools-shared/src/devtools/views/DevTools';
import type {
BrowserTheme,
Wall,
} from 'react-devtools-shared/src/frontend/types';
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
type Config = {
checkBridgeProtocolCompatibility?: boolean,
supportsNativeInspection?: boolean,
supportsProfiling?: boolean,
};
export function createBridge(wall?: Wall): FrontendBridge {
if (wall != null) {
return new Bridge(wall);
}
return new Bridge({listen: () => {}, send: () => {}});
}
export function createStore(bridge: FrontendBridge, config?: Config): Store {
return new Store(bridge, {
checkBridgeProtocolCompatibility: true,
supportsTraceUpdates: true,
supportsNativeInspection: true,
...config,
});
}
type InitializationOptions = {
bridge: FrontendBridge,
store: Store,
theme?: BrowserTheme,
};
export function initialize(
contentWindow: Element | Document,
options: InitializationOptions,
): void {
const {bridge, store, theme = 'light'} = options;
const root = createRoot(contentWindow);
root.render(
<DevTools
bridge={bridge}
browserTheme={theme}
store={store}
showTabBar={true}
warnIfLegacyBackendDetected={true}
/>,
);
}