MCPcopy Index your code
hub / github.com/react/react / inspectElement

Function inspectElement

packages/react-devtools-shared/src/backend/fiber/renderer.js:7044–7205  ·  view source on GitHub ↗
(
    requestID: number,
    id: number,
    path: Array<string | number> | null,
    forceFullData: boolean,
  )

Source from the content-addressed store, hash-verified

7042 }
7043
7044 function inspectElement(
7045 requestID: number,
7046 id: number,
7047 path: Array<string | number> | null,
7048 forceFullData: boolean,
7049 ): InspectedElementPayload {
7050 if (path !== null) {
7051 mergeInspectedPaths(path);
7052 }
7053
7054 if (isMostRecentlyInspectedElement(id) && !forceFullData) {
7055 if (!hasElementUpdatedSinceLastInspected) {
7056 if (path !== null) {
7057 let secondaryCategory: 'suspendedBy' | 'hooks' | null = null;
7058 if (path[0] === 'hooks') {
7059 secondaryCategory = 'hooks';
7060 }
7061
7062 // If this element has not been updated since it was last inspected,
7063 // we can just return the subset of data in the newly-inspected path.
7064 return {
7065 id,
7066 responseID: requestID,
7067 type: 'hydrated-path',
7068 path,
7069 value: cleanForBridge(
7070 getInObject(
7071 ((mostRecentlyInspectedElement: any): InspectedElement),
7072 path,
7073 ),
7074 createIsPathAllowed(null, secondaryCategory),
7075 path,
7076 ),
7077 };
7078 } else {
7079 // If this element has not been updated since it was last inspected, we don't need to return it.
7080 // Instead we can just return the ID to indicate that it has not changed.
7081 return {
7082 id,
7083 responseID: requestID,
7084 type: 'no-change',
7085 };
7086 }
7087 }
7088 } else {
7089 currentlyInspectedPaths = {};
7090 }
7091
7092 hasElementUpdatedSinceLastInspected = false;
7093
7094 try {
7095 mostRecentlyInspectedElement = inspectElementRaw(id);
7096 } catch (error) {
7097 // the error name is synced with ReactDebugHooks
7098 if (error.name === 'ReactDebugToolsRenderError') {
7099 let message = 'Error rendering inspected element.';
7100 let stack;
7101 // Log error & cause for user to debug

Callers

nothing calls this directly

Calls 9

cleanForBridgeFunction · 0.90
getInObjectFunction · 0.90
mergeInspectedPathsFunction · 0.70
createIsPathAllowedFunction · 0.70
inspectElementRawFunction · 0.70
updateSelectedElementFunction · 0.70
errorMethod · 0.65

Tested by

no test coverage detected