Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 30 additions & 0 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,27 @@ function getPublicInstance(instance: HostInstance): HostInstance {
return instance;
}

function getNativeTag(instance: HostInstance): number | null {
if (typeof instance !== 'object' || instance === null) {
return null;
}

// Modern. Fabric.
if (
instance.canonical != null &&
typeof instance.canonical.nativeTag === 'number'
) {
return instance.canonical.nativeTag;
}

// Legacy. Paper.
if (typeof instance._nativeTag === 'number') {
return instance._nativeTag;
}

return null;
}

function aquireHostInstance(
nearestInstance: DevToolsInstance,
hostInstance: HostInstance,
Expand Down Expand Up @@ -4298,6 +4319,11 @@ export function attach(
componentLogsEntry = fiberToComponentLogsMap.get(fiber.alternate);
}

let nativeTag = null;
if (elementType === ElementTypeHostComponent) {
nativeTag = getNativeTag(fiber.stateNode);
}

return {
id: fiberInstance.id,

Expand Down Expand Up @@ -4364,6 +4390,8 @@ export function attach(
rendererVersion: renderer.version,

plugins,

nativeTag,
};
}

Expand Down Expand Up @@ -4457,6 +4485,8 @@ export function attach(
rendererVersion: renderer.version,

plugins,

nativeTag: null,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/backend/legacy/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ export function attach(
plugins: {
stylex: null,
},

nativeTag: null,
};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ export type InspectedElement = {

// UI plugins/visualizations for the inspected element.
plugins: Plugins,

// React Native only.
nativeTag: number | null,
};

export const InspectElementErrorType = 'error';
Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/backendAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export function convertInspectedElementBackendToFrontend(
key,
errors,
warnings,
nativeTag,
} = inspectedElementBackend;

const inspectedElement: InspectedElementFrontend = {
Expand Down Expand Up @@ -273,6 +274,7 @@ export function convertInspectedElementBackendToFrontend(
state: hydrateHelper(state),
errors,
warnings,
nativeTag,
};

return inspectedElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@ import * as React from 'react';

import Badge from './Badge';
import ForgetBadge from './ForgetBadge';
import NativeTagBadge from './NativeTagBadge';

import styles from './InspectedElementBadges.css';

type Props = {
hocDisplayNames: null | Array<string>,
compiledWithForget: boolean,
nativeTag: number | null,
};

export default function InspectedElementBadges({
hocDisplayNames,
compiledWithForget,
nativeTag,
}: Props): React.Node {
if (
!compiledWithForget &&
(hocDisplayNames == null || hocDisplayNames.length === 0)
(hocDisplayNames == null || hocDisplayNames.length === 0) &&
nativeTag === null
) {
return null;
}

return (
<div className={styles.Root}>
{compiledWithForget && <ForgetBadge indexable={false} />}
{nativeTag !== null && <NativeTagBadge nativeTag={nativeTag} />}

{hocDisplayNames !== null &&
hocDisplayNames.map(hocDisplayName => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ export default function InspectedElementView({
toggleParseHookNames,
symbolicatedSourcePromise,
}: Props): React.Node {
const {owners, rendererPackageName, rendererVersion, rootType, source} =
inspectedElement;
const {
owners,
rendererPackageName,
rendererVersion,
rootType,
source,
nativeTag,
} = inspectedElement;

const bridge = useContext(BridgeContext);
const store = useContext(StoreContext);
Expand All @@ -75,6 +81,7 @@ export default function InspectedElementView({
<InspectedElementBadges
hocDisplayNames={element.hocDisplayNames}
compiledWithForget={element.compiledWithForget}
nativeTag={nativeTag}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.Toggle {
display: flex;
}

.Toggle > span { /* targets .ToggleContent */
padding: 0;
}

.Badge {
cursor: help;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import * as React from 'react';

import Badge from './Badge';
import Toggle from '../Toggle';

import styles from './NativeTagBadge.css';

type Props = {
nativeTag: number,
};

const noop = () => {};
const title =
'Unique identifier for the corresponding native component. React Native only.';

export default function NativeTagBadge({nativeTag}: Props): React.Node {
return (
<Toggle onChange={noop} className={styles.Toggle} title={title}>
<Badge className={styles.Badge}>Tag {nativeTag}</Badge>
</Toggle>
);
}
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/frontend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ export type InspectedElement = {

// UI plugins/visualizations for the inspected element.
plugins: Plugins,

// React Native only.
nativeTag: number | null,
};

// TODO: Add profiling type
Expand Down