import type {
ReactRenderer,
RendererInterface,
DevToolsHook,
RendererID,
ProfilingSettings,
} from 'react-devtools-shared/src/backend/types';
import {attach as attachFlight} from 'react-devtools-shared/src/backend/flight/renderer';
import {attach as attachFiber} from 'react-devtools-shared/src/backend/fiber/renderer';
import {attach as attachLegacy} from 'react-devtools-shared/src/backend/legacy/renderer';
import {hasAssignedBackend} from 'react-devtools-shared/src/backend/utils';
function isMatchingRender(version: string): boolean {
return !hasAssignedBackend(version);
}
export default function attachRenderer(
hook: DevToolsHook,
id: RendererID,
renderer: ReactRenderer,
global: Object,
shouldStartProfilingNow: boolean,
profilingSettings: ProfilingSettings,
): RendererInterface | void {
if (!isMatchingRender(renderer.reconcilerVersion || renderer.version)) {
return;
}
let rendererInterface = hook.rendererInterfaces.get(id);
if (rendererInterface == null) {
if (typeof renderer.getCurrentComponentInfo === 'function') {
rendererInterface = attachFlight(hook, id, renderer, global);
} else if (
typeof renderer.findFiberByHostInstance === 'function' ||
renderer.currentDispatcherRef != null
) {
rendererInterface = attachFiber(
hook,
id,
renderer,
global,
shouldStartProfilingNow,
profilingSettings,
);
} else if (renderer.ComponentTree) {
rendererInterface = attachLegacy(hook, id, renderer, global);
} else {
}
}
return rendererInterface;
}