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
15 changes: 13 additions & 2 deletions packages/react-devtools-inline/__tests__/__e2e__/devtools-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,22 @@ async function selectElement(
createTestNameSelector('InspectedElementView-Owners'),
])[0];

if (!ownersList) {
return false;
}

const owners = findAllNodes(ownersList, [
createTestNameSelector('OwnerView'),
]);

return (
title &&
title.innerText.includes(titleText) &&
ownersList &&
ownersList.innerText.includes(ownersListText)
owners &&
owners
.map(node => node.innerText)
.join('\n')
.includes(ownersListText)
);
},
{titleText: displayName, ownersListText: waitForOwnersText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ describe('ProfilingCache', () => {
"hocDisplayNames": null,
"id": 1,
"key": null,
"stack": null,
"type": 11,
},
],
Expand Down
18 changes: 18 additions & 0 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4819,6 +4819,10 @@ export function attach(
id: instance.id,
key: fiber.key,
env: null,
stack:
fiber._debugOwner == null || fiber._debugStack == null
? null
: parseStackTrace(fiber._debugStack, 1),
type: getElementTypeForFiber(fiber),
};
} else {
Expand All @@ -4828,6 +4832,10 @@ export function attach(
id: instance.id,
key: componentInfo.key == null ? null : componentInfo.key,
env: componentInfo.env == null ? null : componentInfo.env,
stack:
componentInfo.owner == null || componentInfo.debugStack == null
? null
: parseStackTrace(componentInfo.debugStack, 1),
type: ElementTypeVirtual,
};
}
Expand Down Expand Up @@ -5426,6 +5434,11 @@ export function attach(

source,

stack:
fiber._debugOwner == null || fiber._debugStack == null
? null
: parseStackTrace(fiber._debugStack, 1),

// Does the component have legacy context attached to it.
hasLegacyContext,

Expand Down Expand Up @@ -5526,6 +5539,11 @@ export function attach(

source,

stack:
componentInfo.owner == null || componentInfo.debugStack == null
? null
: parseStackTrace(componentInfo.debugStack, 1),

// Does the component have legacy context attached to it.
hasLegacyContext: false,

Expand Down
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/backend/legacy/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ export function attach(
id: getID(owner),
key: element.key,
env: null,
stack: null,
type: getElementType(owner),
});
if (owner._currentElement) {
Expand Down Expand Up @@ -837,6 +838,8 @@ export function attach(

source: null,

stack: null,

// Only legacy context exists in legacy versions.
hasLegacyContext: true,

Expand Down
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export type SerializedElement = {
id: number,
key: number | string | null,
env: null | string,
stack: null | ReactStackTrace,
type: ElementType,
};

Expand Down Expand Up @@ -308,6 +309,9 @@ export type InspectedElement = {

source: ReactFunctionLocation | null,

// The location of the JSX creation.
stack: ReactStackTrace | null,

type: ElementType,

// Meta information about the root this element belongs to.
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 @@ -257,6 +257,7 @@ export function convertInspectedElementBackendToFrontend(
owners,
env,
source,
stack,
context,
hooks,
plugins,
Expand Down Expand Up @@ -295,6 +296,7 @@ export function convertInspectedElementBackendToFrontend(
// Previous backend implementations (<= 6.1.5) have a different interface for Source.
// This gates the source features for only compatible backends: >= 6.1.6
source: Array.isArray(source) ? source : null,
stack: stack,
type,
owners:
owners === null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ export default function InspectedElementWrapper(_: Props): React.Node {

const fetchFileWithCaching = useContext(FetchFileWithCachingContext);

const source =
inspectedElement == null
? null
: inspectedElement.source != null
? inspectedElement.source
: inspectedElement.stack != null && inspectedElement.stack.length > 0
? inspectedElement.stack[0]
: null;

const symbolicatedSourcePromise: null | Promise<ReactFunctionLocation | null> =
React.useMemo(() => {
if (inspectedElement == null) return null;
if (fetchFileWithCaching == null) return Promise.resolve(null);

const {source} = inspectedElement;
if (source == null) return Promise.resolve(null);

const [, sourceURL, line, column] = source;
Expand All @@ -66,7 +73,7 @@ export default function InspectedElementWrapper(_: Props): React.Node {
line,
column,
);
}, [inspectedElement]);
}, [source]);

const element =
inspectedElementID !== null
Expand Down Expand Up @@ -223,13 +230,12 @@ export default function InspectedElementWrapper(_: Props): React.Node {

{!alwaysOpenInEditor &&
!!editorURL &&
inspectedElement != null &&
inspectedElement.source != null &&
source != null &&
symbolicatedSourcePromise != null && (
<React.Suspense fallback={<Skeleton height={16} width={24} />}>
<OpenInEditorButton
editorURL={editorURL}
source={inspectedElement.source}
source={source}
symbolicatedSourcePromise={symbolicatedSourcePromise}
/>
</React.Suspense>
Expand Down Expand Up @@ -276,7 +282,7 @@ export default function InspectedElementWrapper(_: Props): React.Node {

{!hideViewSourceAction && (
<InspectedElementViewSourceButton
source={inspectedElement ? inspectedElement.source : null}
source={source}
symbolicatedSourcePromise={symbolicatedSourcePromise}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import InspectedElementSuspendedBy from './InspectedElementSuspendedBy';
import NativeStyleEditor from './NativeStyleEditor';
import {enableStyleXFeatures} from 'react-devtools-feature-flags';
import InspectedElementSourcePanel from './InspectedElementSourcePanel';
import StackTraceView from './StackTraceView';
import OwnerView from './OwnerView';

import styles from './InspectedElementView.css';
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function InspectedElementView({
symbolicatedSourcePromise,
}: Props): React.Node {
const {
stack,
owners,
rendererPackageName,
rendererVersion,
Expand All @@ -68,8 +70,9 @@ export default function InspectedElementView({
? `${rendererPackageName}@${rendererVersion}`
: null;
const showOwnersList = owners !== null && owners.length > 0;
const showStack = stack != null && stack.length > 0;
const showRenderedBy =
showOwnersList || rendererLabel !== null || rootType !== null;
showStack || showOwnersList || rendererLabel !== null || rootType !== null;

return (
<Fragment>
Expand Down Expand Up @@ -168,20 +171,26 @@ export default function InspectedElementView({
data-testname="InspectedElementView-Owners">
<div className={styles.OwnersHeader}>rendered by</div>

{showStack ? <StackTraceView stack={stack} /> : null}
{showOwnersList &&
owners?.map(owner => (
<OwnerView
key={owner.id}
displayName={owner.displayName || 'Anonymous'}
hocDisplayNames={owner.hocDisplayNames}
environmentName={
inspectedElement.env === owner.env ? null : owner.env
}
compiledWithForget={owner.compiledWithForget}
id={owner.id}
isInStore={store.containsElement(owner.id)}
type={owner.type}
/>
<>
<OwnerView
key={owner.id}
displayName={owner.displayName || 'Anonymous'}
hocDisplayNames={owner.hocDisplayNames}
environmentName={
inspectedElement.env === owner.env ? null : owner.env
}
compiledWithForget={owner.compiledWithForget}
id={owner.id}
isInStore={store.containsElement(owner.id)}
type={owner.type}
/>
{owner.stack != null && owner.stack.length > 0 ? (
<StackTraceView stack={owner.stack} />
) : null}
</>
))}

{rootType !== null && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default function OwnerView({
<span className={styles.OwnerContent}>
<span
className={`${styles.Owner} ${isInStore ? '' : styles.NotInStore}`}
title={displayName}>
title={displayName}
data-testname="OwnerView">
{'<' + displayName + '>'}
</span>

Expand Down
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/frontend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export type SerializedElement = {
id: number,
key: number | string | null,
env: null | string,
stack: null | ReactStackTrace,
hocDisplayNames: Array<string> | null,
compiledWithForget: boolean,
type: ElementType,
Expand Down Expand Up @@ -272,6 +273,9 @@ export type InspectedElement = {
// Location of component in source code.
source: ReactFunctionLocation | null,

// The location of the JSX creation.
stack: ReactStackTrace | null,

type: ElementType,

// Meta information about the root this element belongs to.
Expand Down
Loading