Skip to content

Commit 07facb5

Browse files
authored
[Flight] Sort Server Components Track Group ahead of Client Scheduler/Components Tracks (facebook#31736)
Stacked on facebook#31735. This ensures that Server Components Track comes first. Since it's typically rendered first on the server for initial load and then flows into scheduler and client components work. Also puts it closer to the Network and further away from "Main" JS. <img width="769" alt="Screenshot 2024-12-11 at 5 31 41 PM" src="https://github.com/user-attachments/assets/7198db0f-075e-4a78-8ea4-3bfbf06727cb" /> Same trick as in facebook#31615.
1 parent 909ed63 commit 07facb5

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
@@ -69,7 +69,10 @@ import {createBoundServerReference} from './ReactFlightReplyClient';
6969

7070
import {readTemporaryReference} from './ReactFlightTemporaryReferences';
7171

72-
import {logComponentRender} from './ReactFlightPerformanceTrack';
72+
import {
73+
markAllTracksInOrder,
74+
logComponentRender,
75+
} from './ReactFlightPerformanceTrack';
7376

7477
import {
7578
REACT_LAZY_TYPE,
@@ -643,6 +646,7 @@ export function reportGlobalError(response: Response, error: Error): void {
643646
}
644647
});
645648
if (enableProfilerTimer && enableComponentPerformanceTrack) {
649+
markAllTracksInOrder();
646650
flushComponentPerformance(getChunk(response, 0), 0, -Infinity);
647651
}
648652
}

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
@@ -63,7 +63,7 @@ export function setCurrentTrackFromLanes(lanes: Lanes): void {
6363
}
6464

6565
const blockingLaneMarker = {
66-
startTime: 0,
66+
startTime: 0.003,
6767
detail: {
6868
devtools: {
6969
color: 'primary-light',
@@ -74,7 +74,7 @@ const blockingLaneMarker = {
7474
};
7575

7676
const transitionLaneMarker = {
77-
startTime: 0,
77+
startTime: 0.003,
7878
detail: {
7979
devtools: {
8080
color: 'primary-light',
@@ -85,7 +85,7 @@ const transitionLaneMarker = {
8585
};
8686

8787
const suspenseLaneMarker = {
88-
startTime: 0,
88+
startTime: 0.003,
8989
detail: {
9090
devtools: {
9191
color: 'primary-light',
@@ -96,7 +96,7 @@ const suspenseLaneMarker = {
9696
};
9797

9898
const idleLaneMarker = {
99-
startTime: 0,
99+
startTime: 0.003,
100100
detail: {
101101
devtools: {
102102
color: 'primary-light',

0 commit comments

Comments
 (0)