Skip to content

Commit ec98d36

Browse files
authored
[DevTools] Rename Fiber to Element in the Bridge Protocol and RendererInterface (#30490)
I need to start clarifying where things are really actually Fibers and where they're not since I'm adding Server Components as a separate type of component instance which is not backed by a Fiber. Nothing in the front end should really know anything about what kind of renderer implementation we're inspecting and indeed it's already not always a "Fiber" in the legacy renderer. We typically refer to this as a "Component Instance" but the front end currently refers to it as an Element as it historically grew from the browser DevTools Elements tab. I also moved the renderer.js implementation into the `backend/fiber` folder. These are at the same level as `backend/legacy`. This clarifies that anything outside of this folder ideally shouldn't refer to a "Fiber". console.js and profilingHooks.js unfortunately use Fibers a lot which needs further refactoring. The profiler frontend also uses the term alot.
1 parent 941e1b4 commit ec98d36

File tree

20 files changed

+87
-93
lines changed

20 files changed

+87
-93
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ module.exports = {
490490
'packages/react-devtools-extensions/**/*.js',
491491
'packages/react-devtools-shared/src/hook.js',
492492
'packages/react-devtools-shared/src/backend/console.js',
493-
'packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js',
493+
'packages/react-devtools-shared/src/backend/shared/DevToolsComponentStackFrame.js',
494494
],
495495
globals: {
496496
__IS_CHROME__: 'readonly',

packages/react-devtools-extensions/src/contentScripts/renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @flow
99
*/
1010

11-
import {attach} from 'react-devtools-shared/src/backend/renderer';
11+
import {attach} from 'react-devtools-shared/src/backend/fiber/renderer';
1212
import {SESSION_STORAGE_RELOAD_AND_PROFILE_KEY} from 'react-devtools-shared/src/constants';
1313
import {sessionStorageGetItem} from 'react-devtools-shared/src/storage';
1414

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ export default class Agent extends EventEmitter<{
188188
this._bridge = bridge;
189189

190190
bridge.addListener('clearErrorsAndWarnings', this.clearErrorsAndWarnings);
191-
bridge.addListener('clearErrorsForFiberID', this.clearErrorsForFiberID);
192-
bridge.addListener('clearWarningsForFiberID', this.clearWarningsForFiberID);
191+
bridge.addListener('clearErrorsForElementID', this.clearErrorsForElementID);
192+
bridge.addListener(
193+
'clearWarningsForElementID',
194+
this.clearWarningsForElementID,
195+
);
193196
bridge.addListener('copyElementPath', this.copyElementPath);
194197
bridge.addListener('deletePath', this.deletePath);
195198
bridge.addListener('getBackendVersion', this.getBackendVersion);
@@ -270,24 +273,27 @@ export default class Agent extends EventEmitter<{
270273
}
271274
};
272275

273-
clearErrorsForFiberID: ElementAndRendererID => void = ({id, rendererID}) => {
276+
clearErrorsForElementID: ElementAndRendererID => void = ({
277+
id,
278+
rendererID,
279+
}) => {
274280
const renderer = this._rendererInterfaces[rendererID];
275281
if (renderer == null) {
276282
console.warn(`Invalid renderer id "${rendererID}"`);
277283
} else {
278-
renderer.clearErrorsForFiberID(id);
284+
renderer.clearErrorsForElementID(id);
279285
}
280286
};
281287

282-
clearWarningsForFiberID: ElementAndRendererID => void = ({
288+
clearWarningsForElementID: ElementAndRendererID => void = ({
283289
id,
284290
rendererID,
285291
}) => {
286292
const renderer = this._rendererInterfaces[rendererID];
287293
if (renderer == null) {
288294
console.warn(`Invalid renderer id "${rendererID}"`);
289295
} else {
290-
renderer.clearWarningsForFiberID(id);
296+
renderer.clearWarningsForElementID(id);
291297
}
292298
};
293299

@@ -361,7 +367,7 @@ export default class Agent extends EventEmitter<{
361367
const rendererInterface = this.getBestMatchingRendererInterface(node);
362368
if (rendererInterface != null) {
363369
try {
364-
return rendererInterface.getFiberIDForNative(node, true);
370+
return rendererInterface.getElementIDForNative(node, true);
365371
} catch (error) {
366372
// Some old React versions might throw if they can't find a match.
367373
// If so we should ignore it...
@@ -613,7 +619,7 @@ export default class Agent extends EventEmitter<{
613619
selectNode(target: Object): void {
614620
const id = this.getIDForNode(target);
615621
if (id !== null) {
616-
this._bridge.send('selectFiber', id);
622+
this._bridge.send('selectElement', id);
617623
}
618624
}
619625

@@ -820,7 +826,7 @@ export default class Agent extends EventEmitter<{
820826
if (prevMatchID !== nextMatchID) {
821827
if (nextMatchID !== null) {
822828
// We moved forward, unlocking a deeper node.
823-
this._bridge.send('selectFiber', nextMatchID);
829+
this._bridge.send('selectElement', nextMatchID);
824830
}
825831
}
826832
if (nextMatch !== null && nextMatch.isFullMatch) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import {
2525
ANSI_STYLE_DIMMING_TEMPLATE,
2626
ANSI_STYLE_DIMMING_TEMPLATE_WITH_COMPONENT_STACK,
2727
} from 'react-devtools-shared/src/constants';
28-
import {getInternalReactConstants, getDispatcherRef} from './renderer';
28+
import {getInternalReactConstants, getDispatcherRef} from './fiber/renderer';
2929
import {
3030
getStackByFiberInDevAndProd,
3131
getOwnerStackByFiberInDev,
3232
supportsOwnerStacks,
3333
supportsNativeConsoleTasks,
34-
} from './DevToolsFiberComponentStack';
35-
import {formatOwnerStack} from './DevToolsOwnerStack';
34+
} from './fiber/DevToolsFiberComponentStack';
35+
import {formatOwnerStack} from './shared/DevToolsOwnerStack';
3636
import {castBool, castBrowserTheme} from '../utils';
3737

3838
const OVERRIDE_CONSOLE_METHODS = ['error', 'trace', 'warn'];

packages/react-devtools-shared/src/backend/DevToolsFiberComponentStack.js renamed to packages/react-devtools-shared/src/backend/fiber/DevToolsFiberComponentStack.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// (which use different values for ReactTypeOfWork).
1414

1515
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
16-
import type {CurrentDispatcherRef, WorkTagMap} from './types';
16+
import type {CurrentDispatcherRef, WorkTagMap} from '../types';
1717

1818
import type {ReactComponentInfo} from 'shared/ReactTypes';
1919

@@ -22,9 +22,9 @@ import {
2222
describeFunctionComponentFrame,
2323
describeClassComponentFrame,
2424
describeDebugInfoFrame,
25-
} from './DevToolsComponentStackFrame';
25+
} from '../shared/DevToolsComponentStackFrame';
2626

27-
import {formatOwnerStack} from './DevToolsOwnerStack';
27+
import {formatOwnerStack} from '../shared/DevToolsOwnerStack';
2828

2929
export function describeFiber(
3030
workTagMap: WorkTagMap,

packages/react-devtools-shared/src/backend/renderer.js renamed to packages/react-devtools-shared/src/backend/fiber/renderer.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {
5252
copyWithRename,
5353
copyWithSet,
5454
getEffectDurations,
55-
} from './utils';
55+
} from '../utils';
5656
import {
5757
__DEBUG__,
5858
PROFILING_FLAG_BASIC_SUPPORT,
@@ -66,14 +66,14 @@ import {
6666
TREE_OPERATION_SET_SUBTREE_MODE,
6767
TREE_OPERATION_UPDATE_ERRORS_OR_WARNINGS,
6868
TREE_OPERATION_UPDATE_TREE_BASE_DURATION,
69-
} from '../constants';
69+
} from '../../constants';
7070
import {inspectHooksOfFiber} from 'react-debug-tools';
7171
import {
7272
patchConsoleUsingWindowValues,
7373
registerRenderer as registerRendererWithConsole,
7474
patchForStrictMode as patchConsoleForStrictMode,
7575
unpatchForStrictMode as unpatchConsoleForStrictMode,
76-
} from './console';
76+
} from '../console';
7777
import {
7878
CONCURRENT_MODE_NUMBER,
7979
CONCURRENT_MODE_SYMBOL_STRING,
@@ -95,14 +95,14 @@ import {
9595
MEMO_NUMBER,
9696
MEMO_SYMBOL_STRING,
9797
SERVER_CONTEXT_SYMBOL_STRING,
98-
} from './ReactSymbols';
98+
} from '../shared/ReactSymbols';
9999
import {enableStyleXFeatures} from 'react-devtools-feature-flags';
100100
import is from 'shared/objectIs';
101101
import hasOwnProperty from 'shared/hasOwnProperty';
102-
import {getStyleXData} from './StyleX/utils';
103-
import {createProfilingHooks} from './profilingHooks';
102+
import {getStyleXData} from '../StyleX/utils';
103+
import {createProfilingHooks} from '../profilingHooks';
104104

105-
import type {GetTimelineData, ToggleProfilingStatus} from './profilingHooks';
105+
import type {GetTimelineData, ToggleProfilingStatus} from '../profilingHooks';
106106
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
107107
import type {
108108
ChangeDescription,
@@ -122,7 +122,7 @@ import type {
122122
WorkTagMap,
123123
CurrentDispatcherRef,
124124
LegacyDispatcherRef,
125-
} from './types';
125+
} from '../types';
126126
import type {
127127
ComponentFilter,
128128
ElementType,
@@ -811,15 +811,15 @@ export function attach(
811811
}
812812
}
813813

814-
function clearErrorsForFiberID(fiberID: number) {
814+
function clearErrorsForElementID(fiberID: number) {
815815
clearMessageCountHelper(
816816
fiberID,
817817
pendingFiberToErrorsMap,
818818
fiberIDToErrorsMap,
819819
);
820820
}
821821

822-
function clearWarningsForFiberID(fiberID: number) {
822+
function clearWarningsForElementID(fiberID: number) {
823823
clearMessageCountHelper(
824824
fiberID,
825825
pendingFiberToWarningsMap,
@@ -1311,8 +1311,8 @@ export function attach(
13111311
idToArbitraryFiberMap.delete(fiberID);
13121312

13131313
// Also clear any errors/warnings associated with this fiber.
1314-
clearErrorsForFiberID(fiberID);
1315-
clearWarningsForFiberID(fiberID);
1314+
clearErrorsForElementID(fiberID);
1315+
clearWarningsForElementID(fiberID);
13161316
}
13171317

13181318
fiberToIDMap.delete(fiber);
@@ -2862,7 +2862,7 @@ export function attach(
28622862
return fibers;
28632863
}
28642864

2865-
function findNativeNodesForFiberID(id: number) {
2865+
function findNativeNodesForElementID(id: number) {
28662866
try {
28672867
const fiber = findCurrentFiberUsingSlowPathById(id);
28682868
if (fiber === null) {
@@ -2877,7 +2877,7 @@ export function attach(
28772877
}
28782878
}
28792879

2880-
function getDisplayNameForFiberID(id: number): null | string {
2880+
function getDisplayNameForElementID(id: number): null | string {
28812881
const fiber = idToArbitraryFiberMap.get(id);
28822882
return fiber != null ? getDisplayNameForFiber(fiber) : null;
28832883
}
@@ -2886,7 +2886,7 @@ export function attach(
28862886
return renderer.findFiberByHostInstance(hostInstance);
28872887
}
28882888

2889-
function getFiberIDForNative(
2889+
function getElementIDForNative(
28902890
hostInstance: NativeType,
28912891
findNearestUnfilteredAncestor: boolean = false,
28922892
) {
@@ -3870,7 +3870,7 @@ export function attach(
38703870
if (result.hooks !== null) {
38713871
console.log('Hooks:', result.hooks);
38723872
}
3873-
const nativeNodes = findNativeNodesForFiberID(id);
3873+
const nativeNodes = findNativeNodesForElementID(id);
38743874
if (nativeNodes !== null) {
38753875
console.log('Nodes:', nativeNodes);
38763876
}
@@ -4616,7 +4616,7 @@ export function attach(
46164616
traceUpdatesEnabled = isEnabled;
46174617
}
46184618

4619-
function hasFiberWithId(id: number): boolean {
4619+
function hasElementWithId(id: number): boolean {
46204620
return idToArbitraryFiberMap.has(id);
46214621
}
46224622

@@ -4651,26 +4651,24 @@ export function attach(
46514651
return {
46524652
cleanup,
46534653
clearErrorsAndWarnings,
4654-
clearErrorsForFiberID,
4655-
clearWarningsForFiberID,
4654+
clearErrorsForElementID,
4655+
clearWarningsForElementID,
46564656
getSerializedElementValueByPath,
46574657
deletePath,
4658-
findNativeNodesForFiberID,
4658+
findNativeNodesForElementID,
46594659
flushInitialOperations,
46604660
getBestMatchForTrackedPath,
4661-
getComponentStackForFiber,
4662-
getSourceForFiber,
4663-
getDisplayNameForFiberID,
4661+
getDisplayNameForElementID,
46644662
getFiberForNative,
4665-
getFiberIDForNative,
4663+
getElementIDForNative,
46664664
getInstanceAndStyle,
46674665
getOwnersList,
46684666
getPathForElement,
46694667
getProfilingData,
46704668
handleCommitFiberRoot,
46714669
handleCommitFiberUnmount,
46724670
handlePostCommitFiberRoot,
4673-
hasFiberWithId,
4671+
hasElementWithId,
46744672
inspectElement,
46754673
logElementToConsole,
46764674
patchConsoleForStrictMode,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import Agent from './agent';
1111

12-
import {attach} from './renderer';
12+
import {attach} from './fiber/renderer';
1313
import {attach as attachLegacy} from './legacy/renderer';
1414
import {hasAssignedBackend} from './utils';
1515

packages/react-devtools-shared/src/backend/legacy/renderer.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {decorateMany, forceUpdate, restoreMany} from './utils';
3939

4040
import type {
4141
DevToolsHook,
42-
GetFiberIDForNative,
42+
GetElementIDForNative,
4343
InspectedElementPayload,
4444
InstanceAndStyle,
4545
NativeType,
@@ -142,8 +142,8 @@ export function attach(
142142
const internalInstanceToRootIDMap: WeakMap<InternalInstance, number> =
143143
new WeakMap();
144144

145-
let getInternalIDForNative: GetFiberIDForNative =
146-
((null: any): GetFiberIDForNative);
145+
let getInternalIDForNative: GetElementIDForNative =
146+
((null: any): GetElementIDForNative);
147147
let findNativeNodeForInternalID: (id: number) => ?NativeType;
148148
let getFiberForNative = (node: NativeType) => {
149149
// Not implemented.
@@ -174,7 +174,7 @@ export function attach(
174174
};
175175
}
176176

177-
function getDisplayNameForFiberID(id: number): string | null {
177+
function getDisplayNameForElementID(id: number): string | null {
178178
const internalInstance = idToInternalInstanceMap.get(id);
179179
return internalInstance ? getData(internalInstance).displayName : null;
180180
}
@@ -1085,36 +1085,36 @@ export function attach(
10851085
// Not implemented
10861086
}
10871087

1088-
function clearErrorsForFiberID(id: number) {
1088+
function clearErrorsForElementID(id: number) {
10891089
// Not implemented
10901090
}
10911091

1092-
function clearWarningsForFiberID(id: number) {
1092+
function clearWarningsForElementID(id: number) {
10931093
// Not implemented
10941094
}
10951095

10961096
function patchConsoleForStrictMode() {}
10971097

10981098
function unpatchConsoleForStrictMode() {}
10991099

1100-
function hasFiberWithId(id: number): boolean {
1100+
function hasElementWithId(id: number): boolean {
11011101
return idToInternalInstanceMap.has(id);
11021102
}
11031103

11041104
return {
11051105
clearErrorsAndWarnings,
1106-
clearErrorsForFiberID,
1107-
clearWarningsForFiberID,
1106+
clearErrorsForElementID,
1107+
clearWarningsForElementID,
11081108
cleanup,
11091109
getSerializedElementValueByPath,
11101110
deletePath,
11111111
flushInitialOperations,
11121112
getBestMatchForTrackedPath,
1113-
getDisplayNameForFiberID,
1113+
getDisplayNameForElementID,
11141114
getFiberForNative,
1115-
getFiberIDForNative: getInternalIDForNative,
1115+
getElementIDForNative: getInternalIDForNative,
11161116
getInstanceAndStyle,
1117-
findNativeNodesForFiberID: (id: number) => {
1117+
findNativeNodesForElementID: (id: number) => {
11181118
const nativeNode = findNativeNodeForInternalID(id);
11191119
return nativeNode == null ? null : [nativeNode];
11201120
},
@@ -1124,7 +1124,7 @@ export function attach(
11241124
handleCommitFiberRoot,
11251125
handleCommitFiberUnmount,
11261126
handlePostCommitFiberRoot,
1127-
hasFiberWithId,
1127+
hasElementWithId,
11281128
inspectElement,
11291129
logElementToConsole,
11301130
overrideError,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
REACT_TOTAL_NUM_LANES,
3636
SCHEDULING_PROFILER_VERSION,
3737
} from 'react-devtools-timeline/src/constants';
38-
import {describeFiber} from './DevToolsFiberComponentStack';
38+
import {describeFiber} from './fiber/DevToolsFiberComponentStack';
3939

4040
// Add padding to the start/stop time of the profile.
4141
// This makes the UI nicer to use.

0 commit comments

Comments
 (0)