Skip to content

Commit 47ba264

Browse files
author
Brian Vaughn
committed
Fixed edge case bug in Profiler
1 parent d5f1b06 commit 47ba264

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
@@ -1624,18 +1624,25 @@ export function attach(
16241624
pendingOperations.push(op);
16251625
}
16261626

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

16411648
if (pendingOperationsQueue !== null) {
@@ -1668,7 +1675,7 @@ export function attach(
16681675

16691676
recordPendingErrorsAndWarnings();
16701677

1671-
if (pendingOperations.length === 0) {
1678+
if (shouldBailoutWithPendingOperations()) {
16721679
// No warnings or errors to flush; we can bail out early here too.
16731680
return;
16741681
}
@@ -1791,12 +1798,7 @@ export function attach(
17911798
// We do this just before flushing, so we can ignore errors for no-longer-mounted Fibers.
17921799
recordPendingErrorsAndWarnings();
17931800

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

18131813
const numUnmountIDs =
@@ -2724,12 +2724,7 @@ export function attach(
27242724
}
27252725

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

0 commit comments

Comments
 (0)