Skip to content

Commit aa1bfaf

Browse files
author
Brian Vaughn
committed
Fixed edge case bug in Profiler
1 parent f6c130f commit aa1bfaf

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

packages/react-devtools-shared/src/__tests__/__snapshots__/profilingCache-test.js.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,8 +2778,12 @@ Object {
27782778
1,
27792779
0,
27802780
2,
2781-
1,
2781+
5,
27822782
4,
2783+
11,
2784+
10,
2785+
8,
2786+
7,
27832787
],
27842788
],
27852789
"rootID": 1,
@@ -3279,8 +3283,12 @@ Object {
32793283
1,
32803284
0,
32813285
2,
3282-
1,
3286+
5,
32833287
4,
3288+
11,
3289+
10,
3290+
8,
3291+
7,
32843292
],
32853293
],
32863294
"rootID": 1,

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,18 +1622,25 @@ export function attach(
16221622
pendingOperations.push(op);
16231623
}
16241624

1625-
function flushOrQueueOperations(operations: OperationsArray): void {
1626-
if (operations.length === 3) {
1627-
// This operations array is a no op: [renderer ID, root ID, string table size (0)]
1628-
// We can usually skip sending updates like this across the bridge, unless we're Profiling.
1629-
// In that case, even though the tree didn't change– some Fibers may have still rendered.
1630-
if (
1631-
!isProfiling ||
1625+
function shouldBailoutWithPendingOperations() {
1626+
if (!isProfiling) {
1627+
return (
1628+
pendingOperations.length === 0 &&
1629+
pendingRealUnmountedIDs.length === 0 &&
1630+
pendingSimulatedUnmountedIDs.length === 0 &&
1631+
pendingUnmountedRootID === null
1632+
);
1633+
} else {
1634+
return (
16321635
currentCommitProfilingMetadata == null ||
16331636
currentCommitProfilingMetadata.durations.length === 0
1634-
) {
1635-
return;
1636-
}
1637+
);
1638+
}
1639+
}
1640+
1641+
function flushOrQueueOperations(operations: OperationsArray): void {
1642+
if (shouldBailoutWithPendingOperations()) {
1643+
return;
16371644
}
16381645

16391646
if (pendingOperationsQueue !== null) {
@@ -1666,7 +1673,7 @@ export function attach(
16661673

16671674
recordPendingErrorsAndWarnings();
16681675

1669-
if (pendingOperations.length === 0) {
1676+
if (shouldBailoutWithPendingOperations()) {
16701677
// No warnings or errors to flush; we can bail out early here too.
16711678
return;
16721679
}
@@ -1789,12 +1796,7 @@ export function attach(
17891796
// We do this just before flushing, so we can ignore errors for no-longer-mounted Fibers.
17901797
recordPendingErrorsAndWarnings();
17911798

1792-
if (
1793-
pendingOperations.length === 0 &&
1794-
pendingRealUnmountedIDs.length === 0 &&
1795-
pendingSimulatedUnmountedIDs.length === 0 &&
1796-
pendingUnmountedRootID === null
1797-
) {
1799+
if (shouldBailoutWithPendingOperations()) {
17981800
// If we aren't profiling, we can just bail out here.
17991801
// No use sending an empty update over the bridge.
18001802
//
@@ -1803,9 +1805,7 @@ export function attach(
18031805
// (2) the operations array for each commit
18041806
// Because of this, it's important that the operations and metadata arrays align,
18051807
// So it's important not to omit even empty operations while profiling is active.
1806-
if (!isProfiling) {
1807-
return;
1808-
}
1808+
return;
18091809
}
18101810

18111811
const numUnmountIDs =
@@ -2722,12 +2722,7 @@ export function attach(
27222722
}
27232723

27242724
if (isProfiling && isProfilingSupported) {
2725-
// Make sure at least one Fiber performed work during this commit.
2726-
// If not, don't send it to the frontend; showing an empty commit in the Profiler is confusing.
2727-
if (
2728-
currentCommitProfilingMetadata != null &&
2729-
currentCommitProfilingMetadata.durations.length > 0
2730-
) {
2725+
if (!shouldBailoutWithPendingOperations()) {
27312726
const commitProfilingMetadata = ((rootToCommitProfilingMetadataMap: any): CommitProfilingMetadataMap).get(
27322727
currentRootID,
27332728
);

0 commit comments

Comments
 (0)