mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
d962f35cac
In the extension, currently we do the following: 1. check whether there's at least one React renderer on the page 2. if yes, load the backend to the page 3. initialize the backend To support multiple versions of backends, we are changing it to: 1. check the versions of React renders on the page 2. load corresponding React DevTools backends that are shipped with the extension; if they are not contained (usually prod builds of prereleases), show a UI to allow users to load them from UI 3. initialize each of the backends To enable this workflow, a backend will ignore React renderers that does not match its version This PR adds a new file "backendManager" in the extension for this purpose. ------ I've tested it on Chrome, Edge and Firefox extensions
34 lines
929 B
JavaScript
34 lines
929 B
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 type {DevToolsHook} from 'react-devtools-shared/src/backend/types';
|
|
|
|
import Agent from 'react-devtools-shared/src/backend/agent';
|
|
import Bridge from 'react-devtools-shared/src/bridge';
|
|
import {initBackend} from 'react-devtools-shared/src/backend';
|
|
import setupNativeStyleEditor from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';
|
|
|
|
import {COMPACT_VERSION_NAME} from './utils';
|
|
|
|
setup(window.__REACT_DEVTOOLS_GLOBAL_HOOK__);
|
|
|
|
function setup(hook: ?DevToolsHook) {
|
|
if (hook == null) {
|
|
return;
|
|
}
|
|
|
|
hook.backends.set(COMPACT_VERSION_NAME, {
|
|
Agent,
|
|
Bridge,
|
|
initBackend,
|
|
setupNativeStyleEditor,
|
|
});
|
|
hook.emit('devtools-backend-installed', COMPACT_VERSION_NAME);
|
|
}
|