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
28 changes: 21 additions & 7 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,7 @@ export function attach(
}
let start = -1;
let end = -1;
let byteSize = 0;
// $FlowFixMe[method-unbinding]
if (typeof performance.getEntriesByType === 'function') {
// We may be able to collect the start and end time of this resource from Performance Observer.
Expand All @@ -3352,6 +3353,8 @@ export function attach(
if (resourceEntry.name === href) {
start = resourceEntry.startTime;
end = start + resourceEntry.duration;
// $FlowFixMe[prop-missing]
byteSize = (resourceEntry.transferSize: any) || 0;
}
}
}
Expand All @@ -3367,6 +3370,10 @@ export function attach(
// $FlowFixMe: This field doesn't usually take a Fiber but we're only using inside this file.
owner: fiber, // Allow linking to the <link> if it's not filtered.
};
if (byteSize > 0) {
// $FlowFixMe[cannot-write]
ioInfo.byteSize = byteSize;
}
const asyncInfo: ReactAsyncInfo = {
awaited: ioInfo,
// $FlowFixMe: This field doesn't usually take a Fiber but we're only using inside this file.
Expand Down Expand Up @@ -3431,6 +3438,7 @@ export function attach(
}
let start = -1;
let end = -1;
let byteSize = 0;
let fileSize = 0;
// $FlowFixMe[method-unbinding]
if (typeof performance.getEntriesByType === 'function') {
Expand All @@ -3442,7 +3450,9 @@ export function attach(
start = resourceEntry.startTime;
end = start + resourceEntry.duration;
// $FlowFixMe[prop-missing]
fileSize = (resourceEntry.encodedBodySize: any) || 0;
fileSize = (resourceEntry.decodedBodySize: any) || 0;
// $FlowFixMe[prop-missing]
byteSize = (resourceEntry.transferSize: any) || 0;
}
}
}
Expand Down Expand Up @@ -3476,6 +3486,10 @@ export function attach(
// $FlowFixMe: This field doesn't usually take a Fiber but we're only using inside this file.
owner: fiber, // Allow linking to the <link> if it's not filtered.
};
if (byteSize > 0) {
// $FlowFixMe[cannot-write]
ioInfo.byteSize = byteSize;
}
const asyncInfo: ReactAsyncInfo = {
awaited: ioInfo,
// $FlowFixMe: This field doesn't usually take a Fiber but we're only using inside this file.
Expand Down Expand Up @@ -4704,16 +4718,15 @@ export function attach(
trackDebugInfoFromLazyType(nextFiber);
trackDebugInfoFromUsedThenables(nextFiber);

if (
nextFiber.tag === HostHoistable &&
prevFiber.memoizedState !== nextFiber.memoizedState
) {
if (nextFiber.tag === HostHoistable) {
const nearestInstance = reconcilingParent;
if (nearestInstance === null) {
throw new Error('Did not expect a host hoistable to be the root');
}
releaseHostResource(nearestInstance, prevFiber.memoizedState);
aquireHostResource(nearestInstance, nextFiber.memoizedState);
if (prevFiber.memoizedState !== nextFiber.memoizedState) {
releaseHostResource(nearestInstance, prevFiber.memoizedState);
aquireHostResource(nearestInstance, nextFiber.memoizedState);
}
trackDebugInfoFromHostResource(nearestInstance, nextFiber);
} else if (
nextFiber.tag === HostComponent ||
Expand Down Expand Up @@ -5948,6 +5961,7 @@ export function attach(
description: getIODescription(resolvedValue),
start: ioInfo.start,
end: ioInfo.end,
byteSize: ioInfo.byteSize == null ? null : ioInfo.byteSize,
value: ioInfo.value == null ? null : ioInfo.value,
env: ioInfo.env == null ? null : ioInfo.env,
owner:
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export type SerializedIOInfo = {
description: string,
start: number,
end: number,
byteSize: null | number,
value: null | Promise<mixed>,
env: null | string,
owner: null | SerializedElement,
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/backendAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ function backendToFrontendSerializedAsyncInfo(
description: ioInfo.description,
start: ioInfo.start,
end: ioInfo.end,
byteSize: ioInfo.byteSize,
value: ioInfo.value,
env: ioInfo.env,
owner:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ function getShortDescription(name: string, description: string): string {
return '';
}

function formatBytes(bytes: number) {
if (bytes < 1_000) {
return bytes + ' bytes';
}
if (bytes < 1_000_000) {
return (bytes / 1_000).toFixed(1) + ' kB';
}
if (bytes < 1_000_000_000) {
return (bytes / 1_000_000).toFixed(1) + ' mB';
}
return (bytes / 1_000_000_000).toFixed(1) + ' gB';
}

function SuspendedByRow({
bridge,
element,
Expand Down Expand Up @@ -145,7 +158,13 @@ function SuspendedByRow({
<Button
className={styles.CollapsableHeader}
onClick={() => setIsOpen(prevIsOpen => !prevIsOpen)}
title={longName + ' — ' + (end - start).toFixed(2) + ' ms'}>
title={
longName +
' — ' +
(end - start).toFixed(2) +
' ms' +
(ioInfo.byteSize != null ? ' — ' + formatBytes(ioInfo.byteSize) : '')
}>
<ButtonIcon
className={styles.CollapsableHeaderIcon}
type={isOpen ? 'expanded' : 'collapsed'}
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/frontend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export type SerializedIOInfo = {
description: string,
start: number,
end: number,
byteSize: null | number,
value: null | Promise<mixed>,
env: null | string,
owner: null | SerializedElement,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export type ReactIOInfo = {
+name: string, // the name of the async function being called (e.g. "fetch")
+start: number, // the start time
+end: number, // the end time (this might be different from the time the await was unblocked)
+byteSize?: number, // the byte size of this resource across the network. (should only be included if affecting the client.)
+value?: null | Promise<mixed>, // the Promise that was awaited if any, may be rejected
+env?: string, // the environment where this I/O was spawned.
+owner?: null | ReactComponentInfo,
Expand Down
Loading