Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename RendererInterface from Fiber to Element
Except where it's actually expecting a Fiber specifically.
  • Loading branch information
sebmarkbage committed Jul 27, 2024
commit b742aac765c8c64398e712b9823b3feb025ae7d3
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export default class Agent extends EventEmitter<{
const rendererInterface = this.getBestMatchingRendererInterface(node);
if (rendererInterface != null) {
try {
return rendererInterface.getFiberIDForNative(node, true);
return rendererInterface.getElementIDForNative(node, true);
} catch (error) {
// Some old React versions might throw if they can't find a match.
// If so we should ignore it...
Expand Down
18 changes: 9 additions & 9 deletions packages/react-devtools-shared/src/backend/legacy/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {decorateMany, forceUpdate, restoreMany} from './utils';

import type {
DevToolsHook,
GetFiberIDForNative,
GetElementIDForNative,
InspectedElementPayload,
InstanceAndStyle,
NativeType,
Expand Down Expand Up @@ -142,8 +142,8 @@ export function attach(
const internalInstanceToRootIDMap: WeakMap<InternalInstance, number> =
new WeakMap();

let getInternalIDForNative: GetFiberIDForNative =
((null: any): GetFiberIDForNative);
let getInternalIDForNative: GetElementIDForNative =
((null: any): GetElementIDForNative);
let findNativeNodeForInternalID: (id: number) => ?NativeType;
let getFiberForNative = (node: NativeType) => {
// Not implemented.
Expand Down Expand Up @@ -174,7 +174,7 @@ export function attach(
};
}

function getDisplayNameForFiberID(id: number): string | null {
function getDisplayNameForElementID(id: number): string | null {
const internalInstance = idToInternalInstanceMap.get(id);
return internalInstance ? getData(internalInstance).displayName : null;
}
Expand Down Expand Up @@ -1097,7 +1097,7 @@ export function attach(

function unpatchConsoleForStrictMode() {}

function hasFiberWithId(id: number): boolean {
function hasElementWithId(id: number): boolean {
return idToInternalInstanceMap.has(id);
}

Expand All @@ -1110,11 +1110,11 @@ export function attach(
deletePath,
flushInitialOperations,
getBestMatchForTrackedPath,
getDisplayNameForFiberID,
getDisplayNameForElementID,
getFiberForNative,
getFiberIDForNative: getInternalIDForNative,
getElementIDForNative: getInternalIDForNative,
getInstanceAndStyle,
findNativeNodesForFiberID: (id: number) => {
findNativeNodesForElementID: (id: number) => {
const nativeNode = findNativeNodeForInternalID(id);
return nativeNode == null ? null : [nativeNode];
},
Expand All @@ -1124,7 +1124,7 @@ export function attach(
handleCommitFiberRoot,
handleCommitFiberUnmount,
handlePostCommitFiberRoot,
hasFiberWithId,
hasElementWithId,
inspectElement,
logElementToConsole,
overrideError,
Expand Down
18 changes: 9 additions & 9 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2862,7 +2862,7 @@ export function attach(
return fibers;
}

function findNativeNodesForFiberID(id: number) {
function findNativeNodesForElementID(id: number) {
try {
const fiber = findCurrentFiberUsingSlowPathById(id);
if (fiber === null) {
Expand All @@ -2877,7 +2877,7 @@ export function attach(
}
}

function getDisplayNameForFiberID(id: number): null | string {
function getDisplayNameForElementID(id: number): null | string {
const fiber = idToArbitraryFiberMap.get(id);
return fiber != null ? getDisplayNameForFiber(fiber) : null;
}
Expand All @@ -2886,7 +2886,7 @@ export function attach(
return renderer.findFiberByHostInstance(hostInstance);
}

function getFiberIDForNative(
function getElementIDForNative(
hostInstance: NativeType,
findNearestUnfilteredAncestor: boolean = false,
) {
Expand Down Expand Up @@ -3870,7 +3870,7 @@ export function attach(
if (result.hooks !== null) {
console.log('Hooks:', result.hooks);
}
const nativeNodes = findNativeNodesForFiberID(id);
const nativeNodes = findNativeNodesForElementID(id);
if (nativeNodes !== null) {
console.log('Nodes:', nativeNodes);
}
Expand Down Expand Up @@ -4616,7 +4616,7 @@ export function attach(
traceUpdatesEnabled = isEnabled;
}

function hasFiberWithId(id: number): boolean {
function hasElementWithId(id: number): boolean {
return idToArbitraryFiberMap.has(id);
}

Expand Down Expand Up @@ -4655,22 +4655,22 @@ export function attach(
clearWarningsForElementID,
getSerializedElementValueByPath,
deletePath,
findNativeNodesForFiberID,
findNativeNodesForElementID,
flushInitialOperations,
getBestMatchForTrackedPath,
getComponentStackForFiber,
getSourceForFiber,
getDisplayNameForFiberID,
getDisplayNameForElementID,
getFiberForNative,
getFiberIDForNative,
getElementIDForNative,
getInstanceAndStyle,
getOwnersList,
getPathForElement,
getProfilingData,
handleCommitFiberRoot,
handleCommitFiberUnmount,
handlePostCommitFiberRoot,
hasFiberWithId,
hasElementWithId,
inspectElement,
logElementToConsole,
patchConsoleForStrictMode,
Expand Down
21 changes: 6 additions & 15 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ export type WorkTagMap = {
Throw: WorkTag,
};

// TODO: If it's useful for the frontend to know which types of data an Element has
// (e.g. props, state, context, hooks) then we could add a bitmask field for this
// to keep the number of attributes small.
export type FiberData = {
key: string | null,
displayName: string | null,
type: ElementType,
};

export type NativeType = Object;
export type RendererID = number;

Expand All @@ -95,12 +86,12 @@ type SharedInternalsSubset = {
};
export type CurrentDispatcherRef = SharedInternalsSubset;

export type GetDisplayNameForFiberID = (
export type GetDisplayNameForElementID = (
id: number,
findNearestUnfilteredAncestor?: boolean,
) => string | null;

export type GetFiberIDForNative = (
export type GetElementIDForNative = (
component: NativeType,
findNearestUnfilteredAncestor?: boolean,
) => number | null;
Expand Down Expand Up @@ -367,12 +358,12 @@ export type RendererInterface = {
hookID: ?number,
path: Array<string | number>,
) => void,
findNativeNodesForFiberID: FindNativeNodesForFiberID,
findNativeNodesForElementID: FindNativeNodesForFiberID,
flushInitialOperations: () => void,
getBestMatchForTrackedPath: () => PathMatch | null,
getFiberForNative: (component: NativeType) => Fiber | null,
getFiberIDForNative: GetFiberIDForNative,
getDisplayNameForFiberID: GetDisplayNameForFiberID,
getElementIDForNative: GetElementIDForNative,
getDisplayNameForElementID: GetDisplayNameForElementID,
getInstanceAndStyle(id: number): InstanceAndStyle,
getProfilingData(): ProfilingDataBackend,
getOwnersList: (id: number) => Array<SerializedElement> | null,
Expand All @@ -384,7 +375,7 @@ export type RendererInterface = {
handleCommitFiberRoot: (fiber: Object, commitPriority?: number) => void,
handleCommitFiberUnmount: (fiber: Object) => void,
handlePostCommitFiberRoot: (fiber: Object) => void,
hasFiberWithId: (id: number) => boolean,
hasElementWithId: (id: number) => boolean,
inspectElement: (
requestID: number,
id: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ export default class Overlay {
const rendererInterface =
this.agent.getBestMatchingRendererInterface(node);
if (rendererInterface) {
const id = rendererInterface.getFiberIDForNative(node, true);
const id = rendererInterface.getElementIDForNative(node, true);
if (id) {
const ownerName = rendererInterface.getDisplayNameForFiberID(
const ownerName = rendererInterface.getDisplayNameForElementID(
id,
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export default function setupHighlighter(
}

// In some cases fiber may already be unmounted
if (!renderer.hasFiberWithId(id)) {
if (!renderer.hasElementWithId(id)) {
hideOverlay(agent);
return;
}

const nodes: ?Array<HTMLElement> = (renderer.findNativeNodesForFiberID(
const nodes: ?Array<HTMLElement> = (renderer.findNativeNodesForElementID(
id,
): any);

Expand Down