Skip to content

Commit c6984d9

Browse files
committed
Add Flight renderer
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.
1 parent da3471d commit c6984d9

File tree

3 files changed

+117
-3
lines changed

3 files changed

+117
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import type {DevToolsHook, ReactRenderer, RendererInterface} from '../types';
11+
12+
import {
13+
patchConsoleUsingWindowValues,
14+
registerRenderer as registerRendererWithConsole,
15+
} from '../console';
16+
17+
export function attach(
18+
hook: DevToolsHook,
19+
rendererID: number,
20+
renderer: ReactRenderer,
21+
global: Object,
22+
): RendererInterface {
23+
24+
patchConsoleUsingWindowValues();
25+
registerRendererWithConsole(renderer);
26+
27+
return {
28+
cleanup() {},
29+
clearErrorsAndWarnings() {},
30+
clearErrorsForElementID() {},
31+
clearWarningsForElementID() {},
32+
getSerializedElementValueByPath() {},
33+
deletePath() {},
34+
findHostInstancesForElementID() {
35+
return null;
36+
},
37+
flushInitialOperations() {},
38+
getBestMatchForTrackedPath() {
39+
return null;
40+
},
41+
getDisplayNameForElementID() {
42+
return null;
43+
},
44+
getNearestMountedDOMNode() {
45+
return null;
46+
},
47+
getElementIDForHostInstance() {
48+
return null;
49+
},
50+
getInstanceAndStyle() {
51+
return {
52+
instance: null,
53+
style: null,
54+
};
55+
},
56+
getOwnersList() {
57+
return null;
58+
},
59+
getPathForElement() {
60+
return null;
61+
},
62+
getProfilingData() {
63+
throw new Error('getProfilingData not supported by this renderer');
64+
},
65+
handleCommitFiberRoot() {},
66+
handleCommitFiberUnmount() {},
67+
handlePostCommitFiberRoot() {},
68+
hasElementWithId() {
69+
return false;
70+
},
71+
inspectElement(
72+
requestID: number,
73+
id: number,
74+
path: Array<string | number> | null,
75+
) {
76+
return {
77+
id,
78+
responseID: requestID,
79+
type: 'not-found',
80+
};
81+
},
82+
logElementToConsole() {},
83+
patchConsoleForStrictMode() {},
84+
getElementAttributeByPath() {},
85+
getElementSourceFunctionById() {},
86+
overrideError() {},
87+
overrideSuspense() {},
88+
overrideValueAtPath() {},
89+
renamePath() {},
90+
renderer,
91+
setTraceUpdatesEnabled() {},
92+
setTrackedPath() {},
93+
startProfiling() {},
94+
stopProfiling() {},
95+
storeAsGlobal() {},
96+
unpatchConsoleForStrictMode() {},
97+
updateComponentFilters() {},
98+
getEnvironmentNames() {
99+
return [];
100+
},
101+
};
102+
}

packages/react-devtools-shared/src/backend/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
import Agent from './agent';
1111

12-
import {attach} from './fiber/renderer';
12+
import {attach as attachFiber} from './fiber/renderer';
13+
import {attach as attachFlight} from './flight/renderer';
1314
import {attach as attachLegacy} from './legacy/renderer';
15+
1416
import {hasAssignedBackend} from './utils';
1517

1618
import type {DevToolsHook, ReactRenderer, RendererInterface} from './types';
@@ -80,7 +82,10 @@ export function initBackend(
8082
renderer.currentDispatcherRef != null
8183
) {
8284
// react-reconciler v16+
83-
rendererInterface = attach(hook, id, renderer, global);
85+
rendererInterface = attachFiber(hook, id, renderer, global);
86+
} else if (typeof renderer.getCurrentComponentInfo === 'function') {
87+
// react-flight/client
88+
rendererInterface = attachFlight(hook, id, renderer, global);
8489
} else if (renderer.ComponentTree) {
8590
// react-dom v15
8691
rendererInterface = attachLegacy(hook, id, renderer, global);

packages/react-devtools-shared/src/backend/types.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
* Be mindful of backwards compatibility when making changes.
1515
*/
1616

17-
import type {ReactContext, Wakeable} from 'shared/ReactTypes';
17+
import type {
18+
ReactContext,
19+
Wakeable,
20+
ReactComponentInfo,
21+
} from 'shared/ReactTypes';
1822
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1923
import type {
2024
ComponentFilter,
@@ -155,6 +159,9 @@ export type ReactRenderer = {
155159
// Only injected by React v16.9+ in DEV mode.
156160
// Enables DevTools to append owners-only component stack to error messages.
157161
getCurrentFiber?: () => Fiber | null,
162+
// Only injected by React Flight Clients in DEV mode.
163+
// Enables DevTools to append owners-only component stack to error messages from Server Components.
164+
getCurrentComponentInfo?: () => ReactComponentInfo | null,
158165
// 17.0.2+
159166
reconcilerVersion?: string,
160167
// Uniquely identifies React DOM v15.

0 commit comments

Comments
 (0)