mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Allow to use the Profiler when no client is connected in standalone DevTools (#22551)
This commit is contained in:
+20
-1
@@ -30,7 +30,11 @@ import {readFileSync} from 'fs';
|
||||
import {installHook} from 'react-devtools-shared/src/hook';
|
||||
import DevTools from 'react-devtools-shared/src/devtools/views/DevTools';
|
||||
import {doesFilePathExist, launchEditor} from './editor';
|
||||
import {__DEBUG__} from 'react-devtools-shared/src/constants';
|
||||
import {
|
||||
__DEBUG__,
|
||||
LOCAL_STORAGE_DEFAULT_TAB_KEY,
|
||||
} from 'react-devtools-shared/src/constants';
|
||||
import {localStorageSetItem} from '../../react-devtools-shared/src/storage';
|
||||
|
||||
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
|
||||
import type {InspectedElement} from 'react-devtools-shared/src/devtools/views/Components/types';
|
||||
@@ -179,6 +183,20 @@ function onError({code, message}) {
|
||||
}
|
||||
}
|
||||
|
||||
function openProfiler() {
|
||||
// Mocked up bridge and store to allow the DevTools to be rendered
|
||||
bridge = new Bridge({listen: () => {}, send: () => {}});
|
||||
store = new Store(bridge, {});
|
||||
|
||||
// Ensure the Profiler tab is shown initially.
|
||||
localStorageSetItem(
|
||||
LOCAL_STORAGE_DEFAULT_TAB_KEY,
|
||||
JSON.stringify('profiler'),
|
||||
);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
function initialize(socket: WebSocket) {
|
||||
const listeners = [];
|
||||
socket.onmessage = event => {
|
||||
@@ -372,6 +390,7 @@ const DevtoolsUI = {
|
||||
setProjectRoots,
|
||||
setStatusListener,
|
||||
startServer,
|
||||
openProfiler,
|
||||
};
|
||||
|
||||
export default DevtoolsUI;
|
||||
|
||||
@@ -20,6 +20,8 @@ export const TREE_OPERATION_UPDATE_TREE_BASE_DURATION = 4;
|
||||
export const TREE_OPERATION_UPDATE_ERRORS_OR_WARNINGS = 5;
|
||||
export const TREE_OPERATION_REMOVE_ROOT = 6;
|
||||
|
||||
export const LOCAL_STORAGE_DEFAULT_TAB_KEY = 'React::DevTools::defaultTab';
|
||||
|
||||
export const LOCAL_STORAGE_FILTER_PREFERENCES_KEY =
|
||||
'React::DevTools::componentFilters';
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import UnsupportedVersionDialog from './UnsupportedVersionDialog';
|
||||
import WarnIfLegacyBackendDetected from './WarnIfLegacyBackendDetected';
|
||||
import {useLocalStorage} from './hooks';
|
||||
import ThemeProvider from './ThemeProvider';
|
||||
import {LOCAL_STORAGE_DEFAULT_TAB_KEY} from '../../constants';
|
||||
|
||||
import styles from './DevTools.css';
|
||||
|
||||
@@ -143,7 +144,7 @@ export default function DevTools({
|
||||
hideViewSourceAction,
|
||||
}: Props) {
|
||||
const [currentTab, setTab] = useLocalStorage<TabID>(
|
||||
'React::DevTools::defaultTab',
|
||||
LOCAL_STORAGE_DEFAULT_TAB_KEY,
|
||||
defaultTab,
|
||||
);
|
||||
|
||||
|
||||
@@ -142,6 +142,16 @@
|
||||
<strong>before</strong> importing React DOM.
|
||||
</div>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="box-header">Profiler</div>
|
||||
<div class="box-content">
|
||||
Open the <a
|
||||
id="profiler"
|
||||
class="link"
|
||||
href="#"
|
||||
>Profiler tab</a> to inspect saved profiles.
|
||||
</div>
|
||||
</div>
|
||||
<div id="loading-status">Starting the server…</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -201,6 +211,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
function openProfiler() {
|
||||
window.devtools
|
||||
.setContentDOMNode(document.getElementById("container"))
|
||||
.openProfiler();
|
||||
}
|
||||
|
||||
const link = $('#rn-help-link');
|
||||
link.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
@@ -217,6 +233,9 @@
|
||||
$byIp.addEventListener('click', selectAllAndCopy);
|
||||
$byIp.addEventListener('focus', selectAllAndCopy);
|
||||
|
||||
const $profiler = $("#profiler");
|
||||
$profiler.addEventListener('click', openProfiler);
|
||||
|
||||
let devtools;
|
||||
try {
|
||||
devtools = require("react-devtools-core/standalone").default;
|
||||
|
||||
Reference in New Issue
Block a user