Skip to content

Commit

Permalink
Add Flight renderer
Browse files Browse the repository at this point in the history
This represents a virtual renderer that connects to the Flight Client.

This will initially only be used to track console logs but could be expanded to more.
  • Loading branch information
sebmarkbage committed Sep 7, 2024
1 parent da3471d commit f046fe9
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
101 changes: 101 additions & 0 deletions packages/react-devtools-shared/src/backend/flight/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* 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, ReactRenderer, RendererInterface} from '../types';

import {
patchConsoleUsingWindowValues,
registerRenderer as registerRendererWithConsole,
} from '../console';

export function attach(
hook: DevToolsHook,
rendererID: number,
renderer: ReactRenderer,
global: Object,
): RendererInterface {
patchConsoleUsingWindowValues();
registerRendererWithConsole(renderer);

return {
cleanup() {},
clearErrorsAndWarnings() {},
clearErrorsForElementID() {},
clearWarningsForElementID() {},
getSerializedElementValueByPath() {},
deletePath() {},
findHostInstancesForElementID() {
return null;
},
flushInitialOperations() {},
getBestMatchForTrackedPath() {
return null;
},
getDisplayNameForElementID() {
return null;
},
getNearestMountedDOMNode() {
return null;
},
getElementIDForHostInstance() {
return null;
},
getInstanceAndStyle() {
return {
instance: null,
style: null,
};
},
getOwnersList() {
return null;
},
getPathForElement() {
return null;
},
getProfilingData() {
throw new Error('getProfilingData not supported by this renderer');
},
handleCommitFiberRoot() {},
handleCommitFiberUnmount() {},
handlePostCommitFiberRoot() {},
hasElementWithId() {
return false;
},
inspectElement(
requestID: number,
id: number,
path: Array<string | number> | null,
) {
return {
id,
responseID: requestID,
type: 'not-found',
};
},
logElementToConsole() {},
patchConsoleForStrictMode() {},
getElementAttributeByPath() {},
getElementSourceFunctionById() {},
overrideError() {},
overrideSuspense() {},
overrideValueAtPath() {},
renamePath() {},
renderer,
setTraceUpdatesEnabled() {},
setTrackedPath() {},
startProfiling() {},
stopProfiling() {},
storeAsGlobal() {},
unpatchConsoleForStrictMode() {},
updateComponentFilters() {},
getEnvironmentNames() {
return [];
},
};
}
9 changes: 7 additions & 2 deletions packages/react-devtools-shared/src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import Agent from './agent';

import {attach} from './fiber/renderer';
import {attach as attachFiber} from './fiber/renderer';
import {attach as attachFlight} from './flight/renderer';
import {attach as attachLegacy} from './legacy/renderer';

import {hasAssignedBackend} from './utils';

import type {DevToolsHook, ReactRenderer, RendererInterface} from './types';
Expand Down Expand Up @@ -80,7 +82,10 @@ export function initBackend(
renderer.currentDispatcherRef != null
) {
// react-reconciler v16+
rendererInterface = attach(hook, id, renderer, global);
rendererInterface = attachFiber(hook, id, renderer, global);
} else if (typeof renderer.getCurrentComponentInfo === 'function') {
// react-flight/client
rendererInterface = attachFlight(hook, id, renderer, global);
} else if (renderer.ComponentTree) {
// react-dom v15
rendererInterface = attachLegacy(hook, id, renderer, global);
Expand Down
9 changes: 8 additions & 1 deletion packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* Be mindful of backwards compatibility when making changes.
*/

import type {ReactContext, Wakeable} from 'shared/ReactTypes';
import type {
ReactContext,
Wakeable,
ReactComponentInfo,
} from 'shared/ReactTypes';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {
ComponentFilter,
Expand Down Expand Up @@ -155,6 +159,9 @@ export type ReactRenderer = {
// Only injected by React v16.9+ in DEV mode.
// Enables DevTools to append owners-only component stack to error messages.
getCurrentFiber?: () => Fiber | null,
// Only injected by React Flight Clients in DEV mode.
// Enables DevTools to append owners-only component stack to error messages from Server Components.
getCurrentComponentInfo?: () => ReactComponentInfo | null,
// 17.0.2+
reconcilerVersion?: string,
// Uniquely identifies React DOM v15.
Expand Down

0 comments on commit f046fe9

Please sign in to comment.