Skip to content

Commit 0ca49ea

Browse files
committed
Add color variation automatically based on mod of the name
Helps distinguish various helpers like fetch vs query. I also switched dedupes to use primary/secondary color. It was standing out too much. By using the tertiary color for I/O we can avoid confusing the color with the color Server Components. This lets us associate the I/O track with the await in the Server Components track by using the same color scheme but make it different from Server Component rendering.
1 parent fe7f194 commit 0ca49ea

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,7 @@ function flushComponentPerformance(
28932893
trackIdx,
28942894
parentEndTime,
28952895
previousEndTime,
2896+
response._rootEnvironmentName,
28962897
);
28972898
}
28982899
// Since we didn't bump the track this time, we just return the same track.

packages/react-client/src/ReactFlightPerformanceTrack.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,13 @@ export function logDedupedComponentRender(
175175
trackIdx: number,
176176
startTime: number,
177177
endTime: number,
178+
rootEnv: string,
178179
): void {
179180
if (supportsUserTiming && endTime >= 0 && trackIdx < 10) {
181+
const env = componentInfo.env;
180182
const name = componentInfo.name;
183+
const isPrimaryEnv = env === rootEnv;
184+
const color = isPrimaryEnv ? 'primary-light' : 'secondary-light';
181185
const entryName = name + ' [deduped]';
182186
const debugTask = componentInfo.debugTask;
183187
if (__DEV__ && debugTask) {
@@ -190,7 +194,7 @@ export function logDedupedComponentRender(
190194
endTime,
191195
trackNames[trackIdx],
192196
COMPONENTS_TRACK,
193-
'tertiary-light',
197+
color,
194198
),
195199
);
196200
} else {
@@ -200,20 +204,33 @@ export function logDedupedComponentRender(
200204
endTime,
201205
trackNames[trackIdx],
202206
COMPONENTS_TRACK,
203-
'tertiary-light',
207+
color,
204208
);
205209
}
206210
}
207211
}
208212

213+
function getIOColor(
214+
functionName: string,
215+
): 'tertiary-light' | 'tertiary' | 'tertiary-dark' {
216+
// Add some color variation to be able to distinguish various sources.
217+
switch (functionName.charCodeAt(0) % 3) {
218+
case 0:
219+
return 'tertiary-light';
220+
case 1:
221+
return 'tertiary';
222+
default:
223+
return 'tertiary-dark';
224+
}
225+
}
226+
209227
export function logIOInfo(ioInfo: ReactIOInfo): void {
210228
const startTime = ioInfo.start;
211229
const endTime = ioInfo.end;
212230
if (supportsUserTiming && endTime >= 0) {
213231
const name = ioInfo.name;
214232
const debugTask = ioInfo.debugTask;
215-
// TODO: Add more built-in color assignment.
216-
const color = name === 'fetch' ? 'primary-light' : 'secondary-light';
233+
const color = getIOColor(name);
217234
if (__DEV__ && debugTask) {
218235
debugTask.run(
219236
// $FlowFixMe[method-unbinding]

0 commit comments

Comments
 (0)