Skip to content

Commit 12621f5

Browse files
committed
Add color variation automatically based on mod of the name
Helps distinguish various helpers like fetch vs query. I also switched to using only the primary color. This avoids confusing the secondary color with the color Server Components. This lets us associate the I/O 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 12621f5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/react-client/src/ReactFlightPerformanceTrack.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,27 @@ export function logDedupedComponentRender(
206206
}
207207
}
208208

209+
function getIOColor(
210+
functionName: string,
211+
): 'primary-light' | 'primary' | 'primary-dark' {
212+
// Add some color variation to be able to distinguish various sources.
213+
switch (functionName.charCodeAt(0) % 3) {
214+
case 0:
215+
return 'primary-light';
216+
case 1:
217+
return 'primary';
218+
default:
219+
return 'primary-dark';
220+
}
221+
}
222+
209223
export function logIOInfo(ioInfo: ReactIOInfo): void {
210224
const startTime = ioInfo.start;
211225
const endTime = ioInfo.end;
212226
if (supportsUserTiming && endTime >= 0) {
213227
const name = ioInfo.name;
214228
const debugTask = ioInfo.debugTask;
215-
// TODO: Add more built-in color assignment.
216-
const color = name === 'fetch' ? 'primary-light' : 'secondary-light';
229+
const color = getIOColor(name);
217230
if (__DEV__ && debugTask) {
218231
debugTask.run(
219232
// $FlowFixMe[method-unbinding]

0 commit comments

Comments
 (0)