diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index d08cd8a5ddede..cb3a8f2f407c7 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -237,6 +237,8 @@ export function getInternalReactConstants( HostComponent: 5, HostPortal: 4, HostRoot: 3, + HostResource: 26, // In reality, 18.2+. But doesn't hurt to include it here + HostSingleton: 27, // Same as above HostText: 6, IncompleteClassComponent: 17, IndeterminateComponent: 2, @@ -269,6 +271,8 @@ export function getInternalReactConstants( HostComponent: 5, HostPortal: 4, HostRoot: 3, + HostResource: -1, // Doesn't exist yet + HostSingleton: -1, // Doesn't exist yet HostText: 6, IncompleteClassComponent: 17, IndeterminateComponent: 2, @@ -300,6 +304,8 @@ export function getInternalReactConstants( HostComponent: 5, HostPortal: 4, HostRoot: 3, + HostResource: -1, // Doesn't exist yet + HostSingleton: -1, // Doesn't exist yet HostText: 6, IncompleteClassComponent: 17, IndeterminateComponent: 2, @@ -331,6 +337,8 @@ export function getInternalReactConstants( HostComponent: 7, HostPortal: 6, HostRoot: 5, + HostResource: -1, // Doesn't exist yet + HostSingleton: -1, // Doesn't exist yet HostText: 8, IncompleteClassComponent: -1, // Doesn't exist yet IndeterminateComponent: 4, @@ -362,6 +370,8 @@ export function getInternalReactConstants( HostComponent: 5, HostPortal: 4, HostRoot: 3, + HostResource: -1, // Doesn't exist yet + HostSingleton: -1, // Doesn't exist yet HostText: 6, IncompleteClassComponent: -1, // Doesn't exist yet IndeterminateComponent: 0, @@ -401,6 +411,8 @@ export function getInternalReactConstants( IndeterminateComponent, ForwardRef, HostRoot, + HostResource, + HostSingleton, HostComponent, HostPortal, HostText, @@ -466,6 +478,8 @@ export function getInternalReactConstants( } return null; case HostComponent: + case HostSingleton: + case HostResource: return type; case HostPortal: case HostText: @@ -600,6 +614,8 @@ export function attach( Fragment, FunctionComponent, HostRoot, + HostResource, + HostSingleton, HostPortal, HostComponent, HostText, @@ -1044,6 +1060,8 @@ export function attach( case HostRoot: return ElementTypeRoot; case HostComponent: + case HostResource: + case HostSingleton: return ElementTypeHostComponent; case HostPortal: case HostText: diff --git a/packages/react-devtools-shared/src/backend/types.js b/packages/react-devtools-shared/src/backend/types.js index 0392768613764..ef03c5717a505 100644 --- a/packages/react-devtools-shared/src/backend/types.js +++ b/packages/react-devtools-shared/src/backend/types.js @@ -40,6 +40,8 @@ export type WorkTagMap = { HostComponent: WorkTag, HostPortal: WorkTag, HostRoot: WorkTag, + HostResource: WorkTag, + HostSingleton: WorkTag, HostText: WorkTag, IncompleteClassComponent: WorkTag, IndeterminateComponent: WorkTag, diff --git a/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementStateTree.js b/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementStateTree.js index 6557fddbef985..f3a83da5ea628 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementStateTree.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementStateTree.js @@ -9,6 +9,7 @@ import {copy} from 'clipboard-js'; import * as React from 'react'; +import {ElementTypeHostComponent} from 'react-devtools-shared/src/types'; import Button from '../Button'; import ButtonIcon from '../ButtonIcon'; import KeyValue from './KeyValue'; @@ -33,52 +34,55 @@ export default function InspectedElementStateTree({ inspectedElement, store, }: Props): React.Node { - const {state} = inspectedElement; + const {state, type} = inspectedElement; + + // HostSingleton and HostResource may have state that we don't want to expose to users + const isHostComponent = type === ElementTypeHostComponent; const entries = state != null ? Object.entries(state) : null; + const isEmpty = entries === null || entries.length === 0; + + if (isEmpty || isHostComponent) { + return null; + } + if (entries !== null) { entries.sort(alphaSortEntries); } - const isEmpty = entries === null || entries.length === 0; - const handleCopy = () => copy(serializeDataForCopy(((state: any): Object))); - if (isEmpty) { - return null; - } else { - return ( -
-
-
state
- {!isEmpty && ( - - )} -
- {isEmpty &&
None
} - {!isEmpty && - (entries: any).map(([name, value]) => ( -