@@ -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