/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-devtools-shell/src/perf-regression/devtools.js
54 строки
2 KB
Jan Kassens
[flow] make Flow suppressions explicit on the error (#26487)
27 мар 2023, 14:43
Не верифицирован
27 мар 2023, 14:43
afea1d0
Код
Авторство
О чём код?
import * as React from 'react'; import {createRoot} from 'react-dom/client'; import { activate as activateBackend, initialize as initializeBackend, } from 'react-devtools-inline/backend'; import {initialize as createDevTools} from 'react-devtools-inline/frontend'; // This is a pretty gross hack to make the runtime loaded named-hooks-code work. // TODO (Webpack 5) Hoepfully we can remove this once we upgrade to Webpack 5. __webpack_public_path__ = '/dist/'; // eslint-disable-line no-undef // TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration. function hookNamesModuleLoaderFunction() { return import('react-devtools-inline/hookNames'); } function inject(contentDocument, sourcePath) { const script = contentDocument.createElement('script'); script.src = sourcePath; ((contentDocument.body: any): HTMLBodyElement).appendChild(script); } function init( appSource: string, appIframe: HTMLIFrameElement, devtoolsContainer: HTMLElement, loadDevToolsButton: HTMLButtonElement, ) { const {contentDocument, contentWindow} = appIframe; initializeBackend(contentWindow); inject(contentDocument, appSource); loadDevToolsButton.addEventListener('click', () => { const DevTools = createDevTools(contentWindow); createRoot(devtoolsContainer).render( <DevTools hookNamesModuleLoaderFunction={hookNamesModuleLoaderFunction} showTabBar={true} />, ); activateBackend(contentWindow); }); } init( 'dist/perf-regression-app.js', document.getElementById('iframe'), document.getElementById('devtools'), document.getElementById('load-devtools'), );