Skip to content

Commit 1f6a108

Browse files
committed
Sort Server Components Track Group ahead of Client Scheduler/Components Tracks
1 parent cf39c17 commit 1f6a108

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ import {createBoundServerReference} from './ReactFlightReplyClient';
7171

7272
import {readTemporaryReference} from './ReactFlightTemporaryReferences';
7373

74-
import {logComponentRender} from './ReactFlightPerformanceTrack';
74+
import {
75+
markAllTracksInOrder,
76+
logComponentRender,
77+
} from './ReactFlightPerformanceTrack';
7578

7679
import {
7780
REACT_LAZY_TYPE,
@@ -649,6 +652,7 @@ export function reportGlobalError(response: Response, error: Error): void {
649652
}
650653
});
651654
if (enableProfilerTimer && enableComponentPerformanceTrack) {
655+
markAllTracksInOrder();
652656
flushComponentPerformance(getChunk(response, 0), 0, -Infinity);
653657
}
654658
}

packages/react-client/src/ReactFlightPerformanceTrack.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ const supportsUserTiming =
1919

2020
const COMPONENTS_TRACK = 'Server Components ⚛';
2121

22+
const componentsTrackMarker = {
23+
startTime: 0.001,
24+
detail: {
25+
devtools: {
26+
color: 'primary-light',
27+
track: 'Primary',
28+
trackGroup: COMPONENTS_TRACK,
29+
},
30+
},
31+
};
32+
33+
export function markAllTracksInOrder() {
34+
if (supportsUserTiming) {
35+
// Ensure we create the Server Component track groups earlier than the Client Scheduler
36+
// and Client Components. We can always add the 0 time slot even if it's in the past.
37+
// That's still considered for ordering.
38+
performance.mark('Server Components Track', componentsTrackMarker);
39+
}
40+
}
41+
2242
// Reused to avoid thrashing the GC.
2343
const reusableComponentDevToolDetails = {
2444
color: 'primary',

packages/react-reconciler/src/ReactFiberPerformanceTrack.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function setCurrentTrackFromLanes(lanes: number): void {
5656
}
5757

5858
const blockingLaneMarker = {
59-
startTime: 0,
59+
startTime: 0.003,
6060
detail: {
6161
devtools: {
6262
color: 'primary-light',
@@ -67,7 +67,7 @@ const blockingLaneMarker = {
6767
};
6868

6969
const transitionLaneMarker = {
70-
startTime: 0,
70+
startTime: 0.003,
7171
detail: {
7272
devtools: {
7373
color: 'primary-light',
@@ -78,7 +78,7 @@ const transitionLaneMarker = {
7878
};
7979

8080
const suspenseLaneMarker = {
81-
startTime: 0,
81+
startTime: 0.003,
8282
detail: {
8383
devtools: {
8484
color: 'primary-light',
@@ -89,7 +89,7 @@ const suspenseLaneMarker = {
8989
};
9090

9191
const idleLaneMarker = {
92-
startTime: 0,
92+
startTime: 0.003,
9393
detail: {
9494
devtools: {
9595
color: 'primary-light',

0 commit comments

Comments
 (0)