mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
984ea11d14
## Summary Separate function entry points for `react-devtools-fusebox` into `initializeComponents` and `initializeProfiler`. The motivation behind this change is to separate these tabs into top-level Chrome DevTools panels (aligned with web) in React Native. ## How did you test this change? - Build `react-devtools-fusebox` and load into local [rn-chrome-devtools-frontend](https://github.com/facebookexperimental/rn-chrome-devtools-frontend) project with updated call sites. <img width="1933" alt="image" src="https://github.com/user-attachments/assets/202d32a1-b8da-4936-b0e1-04875a30f256"> <img width="1949" alt="image" src="https://github.com/user-attachments/assets/39dbe154-989c-4f76-b103-aa19f07a3b9c"> ✅ Tabs can be separately initialised in individual Chrome DevTools panels
99 lines
2.6 KiB
JavaScript
99 lines
2.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';
|
|
import type {
|
|
CanViewElementSource,
|
|
TabID,
|
|
ViewAttributeSource,
|
|
ViewElementSource,
|
|
} from 'react-devtools-shared/src/devtools/views/DevTools';
|
|
import type {Config} from 'react-devtools-shared/src/devtools/store';
|
|
|
|
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,
|
|
supportsClickToInspect: true,
|
|
...config,
|
|
});
|
|
}
|
|
|
|
type InitializationOptions = {
|
|
bridge: FrontendBridge,
|
|
store: Store,
|
|
theme?: BrowserTheme,
|
|
viewAttributeSourceFunction?: ViewAttributeSource,
|
|
viewElementSourceFunction?: ViewElementSource,
|
|
canViewElementSourceFunction?: CanViewElementSource,
|
|
};
|
|
|
|
function initializeTab(
|
|
tab: TabID,
|
|
contentWindow: Element | Document,
|
|
options: InitializationOptions,
|
|
) {
|
|
const {
|
|
bridge,
|
|
store,
|
|
theme = 'light',
|
|
viewAttributeSourceFunction,
|
|
viewElementSourceFunction,
|
|
canViewElementSourceFunction,
|
|
} = options;
|
|
const root = createRoot(contentWindow);
|
|
|
|
root.render(
|
|
<DevTools
|
|
bridge={bridge}
|
|
browserTheme={theme}
|
|
store={store}
|
|
showTabBar={false}
|
|
overrideTab={tab}
|
|
warnIfLegacyBackendDetected={true}
|
|
enabledInspectedElementContextMenu={true}
|
|
viewAttributeSourceFunction={viewAttributeSourceFunction}
|
|
viewElementSourceFunction={viewElementSourceFunction}
|
|
canViewElementSourceFunction={canViewElementSourceFunction}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
export function initializeComponents(
|
|
contentWindow: Element | Document,
|
|
options: InitializationOptions,
|
|
): void {
|
|
initializeTab('components', contentWindow, options);
|
|
}
|
|
|
|
export function initializeProfiler(
|
|
contentWindow: Element | Document,
|
|
options: InitializationOptions,
|
|
): void {
|
|
initializeTab('profiler', contentWindow, options);
|
|
}
|