Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] add support for HostSingleton & HostResource #25616

Merged
merged 2 commits into from
Nov 7, 2022
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
18 changes: 18 additions & 0 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export function getInternalReactConstants(
// Currently the version in Git is 17.0.2 (but that version has not been/may not end up being released).
if (gt(version, '17.0.1')) {
ReactTypeOfWork = {
HostSingleton: 27, // In reality, 18.2+. But doesn't hurt to include it here
HostResource: 26, // Same as above
CacheComponent: 24, // Experimental
ClassComponent: 1,
ContextConsumer: 9,
Expand Down Expand Up @@ -256,6 +258,8 @@ export function getInternalReactConstants(
};
} else if (gte(version, '17.0.0-alpha')) {
ReactTypeOfWork = {
HostSingleton: -1, // Doesn't exist yet
mondaychen marked this conversation as resolved.
Show resolved Hide resolved
HostResource: -1, // Doesn't exist yet
CacheComponent: -1, // Doesn't exist yet
ClassComponent: 1,
ContextConsumer: 9,
Expand Down Expand Up @@ -287,6 +291,8 @@ export function getInternalReactConstants(
};
} else if (gte(version, '16.6.0-beta.0')) {
ReactTypeOfWork = {
HostSingleton: -1, // Doesn't exist yet
HostResource: -1, // Doesn't exist yet
CacheComponent: -1, // Doesn't exist yet
ClassComponent: 1,
ContextConsumer: 9,
Expand Down Expand Up @@ -318,6 +324,8 @@ export function getInternalReactConstants(
};
} else if (gte(version, '16.4.3-alpha')) {
ReactTypeOfWork = {
HostSingleton: -1, // Doesn't exist yet
HostResource: -1, // Doesn't exist yet
CacheComponent: -1, // Doesn't exist yet
ClassComponent: 2,
ContextConsumer: 11,
Expand Down Expand Up @@ -349,6 +357,8 @@ export function getInternalReactConstants(
};
} else {
ReactTypeOfWork = {
HostSingleton: -1, // Doesn't exist yet
HostResource: -1, // Doesn't exist yet
CacheComponent: -1, // Doesn't exist yet
ClassComponent: 2,
ContextConsumer: 12,
Expand Down Expand Up @@ -415,6 +425,8 @@ export function getInternalReactConstants(
SuspenseComponent,
SuspenseListComponent,
TracingMarkerComponent,
HostResource,
HostSingleton,
} = ReactTypeOfWork;

function resolveFiberType(type: any) {
Expand Down Expand Up @@ -466,6 +478,8 @@ export function getInternalReactConstants(
}
return null;
case HostComponent:
case HostSingleton:
case HostResource:
return type;
case HostPortal:
case HostText:
Expand Down Expand Up @@ -612,6 +626,8 @@ export function attach(
SuspenseComponent,
SuspenseListComponent,
TracingMarkerComponent,
HostSingleton,
HostResource,
} = ReactTypeOfWork;
const {
ImmediatePriority,
Expand Down Expand Up @@ -1044,6 +1060,8 @@ export function attach(
case HostRoot:
return ElementTypeRoot;
case HostComponent:
case HostResource:
case HostSingleton:
return ElementTypeHostComponent;
case HostPortal:
case HostText:
Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export type WorkTagMap = {
SuspenseListComponent: WorkTag,
TracingMarkerComponent: WorkTag,
YieldComponent: WorkTag,
HostResource: WorkTag,
HostSingleton: WorkTag,
};

// TODO: If it's useful for the frontend to know which types of data an Element has
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,7 +34,11 @@ 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
if (type === ElementTypeHostComponent) {
mondaychen marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

const entries = state != null ? Object.entries(state) : null;
if (entries !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export default function ComponentsSettings(_: {}): React.Node {
<option value={ElementTypeFunction}>function</option>
<option value={ElementTypeForwardRef}>forward ref</option>
<option value={ElementTypeHostComponent}>
host (e.g. &lt;div&gt;)
dom nodes (e.g. &lt;div&gt;)
</option>
<option value={ElementTypeMemo}>memo</option>
<option value={ElementTypeOtherOrUnknown}>other</option>
Expand Down