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 root and renderer version to inspected props panel #18963

Merged
merged 2 commits into from
May 21, 2020
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
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/backend/legacy/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@ export function attach(

// Location of component in source coude.
source,

rootType: null,
rendererPackageName: null,
rendererVersion: null,
};
}

Expand Down
14 changes: 14 additions & 0 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,16 @@ export function attach(
}
}

let rootType = null;
let current = fiber;
while (current.return !== null) {
current = current.return;
}
const fiberRoot = current.stateNode;
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
rootType = fiberRoot._debugRootType;
}

return {
id,

Expand Down Expand Up @@ -2318,6 +2328,10 @@ export function attach(

// Location of component in source coude.
source: _debugSource || null,

rootType,
rendererPackageName: renderer.rendererPackageName,
rendererVersion: renderer.version,
};
}

Expand Down
10 changes: 9 additions & 1 deletion packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type ReactProviderType<T> = {
export type ReactRenderer = {
findFiberByHostInstance: (hostInstance: NativeType) => ?Fiber,
version: string,
rendererPackageName: string,
bundleType: BundleType,
// 16.9+
overrideHookState?: ?(
Expand Down Expand Up @@ -207,10 +208,17 @@ export type InspectedElement = {|
// List of owners
owners: Array<Owner> | null,

// Location of component in source coude.
// Location of component in source code.
source: Source | null,

type: ElementType,

// Meta information about the root this element belongs to.
rootType: string | null,

// Meta information about the renderer that created this element.
rendererPackageName: string | null,
rendererVersion: string | null,
|};

export const InspectElementFullDataType = 'full-data';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export default function Badge({
type,
children,
}: Props) {
let totalBadgeCount = 0;

if (hocDisplayNames !== null) {
totalBadgeCount += hocDisplayNames.length;
if (hocDisplayNames === null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a regression from #18802 I think.

return null;
}

const totalBadgeCount = hocDisplayNames.length;

return (
<Fragment>
<div className={`${styles.Badge} ${className || ''}`}>{children}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ function InspectedElementContextController({children}: Props) {
context,
hooks,
props,
rendererPackageName,
rendererVersion,
rootType,
state,
key,
} = ((data.value: any): InspectedElementBackend);
Expand All @@ -220,6 +223,9 @@ function InspectedElementContextController({children}: Props) {
hasLegacyContext,
id,
key,
rendererPackageName,
rendererVersion,
rootType,
source,
type,
owners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,10 @@
.ContextMenuIcon {
margin-right: 0.5rem;
}

.OwnersMetaField {
padding-left: 1.25rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import type {
InspectedElementContextType,
StoreAsGlobal,
} from './InspectedElementContext';
import type {Element, InspectedElement} from './types';
import type {Element, InspectedElement, Owner} from './types';
import type {ElementType} from 'react-devtools-shared/src/types';

export type Props = {||};
Expand Down Expand Up @@ -291,11 +291,13 @@ function InspectedElementView({
hooks,
owners,
props,
rendererPackageName,
rendererVersion,
rootType,
source,
state,
} = inspectedElement;

const {ownerID} = useContext(TreeStateContext);
const bridge = useContext(BridgeContext);
const store = useContext(StoreContext);

Expand Down Expand Up @@ -374,6 +376,14 @@ function InspectedElementView({
};
}

const rendererLabel =
rendererPackageName !== null && rendererVersion !== null
? `${rendererPackageName}@${rendererVersion}`
: null;
const showOwnersList = owners !== null && owners.length > 0;
const showRenderedBy =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll always show this section now, except for v15.

showOwnersList || rendererLabel !== null || rootType !== null;

return (
<Fragment>
<div className={styles.InspectedElement}>
Expand Down Expand Up @@ -415,19 +425,26 @@ function InspectedElementView({

<NativeStyleEditor />

{ownerID === null && owners !== null && owners.length > 0 && (
{showRenderedBy && (
<div className={styles.Owners}>
<div className={styles.OwnersHeader}>rendered by</div>
{owners.map(owner => (
<OwnerView
key={owner.id}
displayName={owner.displayName || 'Anonymous'}
hocDisplayNames={owner.hocDisplayNames}
id={owner.id}
isInStore={store.containsElement(owner.id)}
type={owner.type}
/>
))}
{showOwnersList &&
((owners: any): Array<Owner>).map(owner => (
<OwnerView
key={owner.id}
displayName={owner.displayName || 'Anonymous'}
hocDisplayNames={owner.hocDisplayNames}
id={owner.id}
isInStore={store.containsElement(owner.id)}
type={owner.type}
/>
))}
{rootType !== null && (
<div className={styles.OwnersMetaField}>{rootType}</div>
)}
{rendererLabel !== null && (
<div className={styles.OwnersMetaField}>{rendererLabel}</div>
)}
</div>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export type InspectedElement = {|
source: Source | null,

type: ElementType,

// Meta information about the root this element belongs to.
rootType: string | null,

// Meta information about the renderer that created this element.
rendererPackageName: string | null,
rendererVersion: string | null,
|};

// TODO: Add profiling type
Expand Down
15 changes: 15 additions & 0 deletions packages/react-reconciler/src/ReactFiberRoot.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from 'shared/ReactFeatureFlags';
import {unstable_getThreadID} from 'scheduler/tracing';
import {initializeUpdateQueue} from './ReactUpdateQueue.new';
import {LegacyRoot, BlockingRoot, ConcurrentRoot} from './ReactRootTags';

function FiberRootNode(containerInfo, tag, hydrate) {
this.tag = tag;
Expand Down Expand Up @@ -60,6 +61,20 @@ function FiberRootNode(containerInfo, tag, hydrate) {
if (enableSuspenseCallback) {
this.hydrationCallbacks = null;
}

if (__DEV__) {
switch (tag) {
case BlockingRoot:
this._debugRootType = 'createBlockingRoot()';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This minimizes the coupling between React and DevTools.

break;
case ConcurrentRoot:
this._debugRootType = 'createRoot()';
break;
case LegacyRoot:
this._debugRootType = 'createLegacyRoot()';
break;
}
}
}

export function createFiberRoot(
Expand Down
15 changes: 15 additions & 0 deletions packages/react-reconciler/src/ReactFiberRoot.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {unstable_getThreadID} from 'scheduler/tracing';
import {NoPriority} from './SchedulerWithReactIntegration.old';
import {initializeUpdateQueue} from './ReactUpdateQueue.old';
import {clearPendingUpdates as clearPendingMutableSourceUpdates} from './ReactMutableSource.old';
import {LegacyRoot, BlockingRoot, ConcurrentRoot} from './ReactRootTags';

function FiberRootNode(containerInfo, tag, hydrate) {
this.tag = tag;
Expand Down Expand Up @@ -54,6 +55,20 @@ function FiberRootNode(containerInfo, tag, hydrate) {
if (enableSuspenseCallback) {
this.hydrationCallbacks = null;
}

if (__DEV__) {
switch (tag) {
case BlockingRoot:
this._debugRootType = 'createBlockingRoot()';
break;
case ConcurrentRoot:
this._debugRootType = 'createRoot()';
break;
case LegacyRoot:
this._debugRootType = 'createLegacyRoot()';
break;
}
}
}

export function createFiberRoot(
Expand Down