Skip to content

Commit 6ef4ceb

Browse files
committed
Use different color configurations for different environments
1 parent 472775b commit 6ef4ceb

File tree

6 files changed

+77
-12
lines changed

6 files changed

+77
-12
lines changed

packages/react-devtools-shared/src/devtools/constants.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ export const THEME_STYLES: {[style: Theme | DisplayDensity]: any, ...} = {
154154
'--color-warning-text-color': '#ffffff',
155155
'--color-warning-text-color-inverted': '#fd4d69',
156156

157-
'--color-suspense': '#0088fa',
158-
'--color-transition': '#6a51b2',
157+
'--color-suspense-default': '#0088fa',
158+
'--color-transition-default': '#6a51b2',
159159
'--color-suspense-server': '#62bc6a',
160160
'--color-transition-server': '#3f7844',
161161
'--color-suspense-other': '#f3ce49',
@@ -315,8 +315,8 @@ export const THEME_STYLES: {[style: Theme | DisplayDensity]: any, ...} = {
315315
'--color-warning-text-color': '#ffffff',
316316
'--color-warning-text-color-inverted': '#ee1638',
317317

318-
'--color-suspense': '#61dafb',
319-
'--color-transition': '#6a51b2',
318+
'--color-suspense-default': '#61dafb',
319+
'--color-transition-default': '#6a51b2',
320320
'--color-suspense-server': '#62bc6a',
321321
'--color-transition-server': '#3f7844',
322322
'--color-suspense-other': '#f3ce49',

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementSuspendedBy.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import OwnerView from './OwnerView';
2222
import {meta} from '../../../hydration';
2323
import useInferredName from '../useInferredName';
2424

25+
import {getClassNameForEnvironment} from '../SuspenseTab/SuspenseEnvironmentColors.js';
26+
2527
import type {
2628
InspectedElement,
2729
SerializedAsyncInfo,
@@ -181,7 +183,12 @@ function SuspendedByRow({
181183
</>
182184
)}
183185
<div className={styles.CollapsableHeaderFiller} />
184-
<div className={styles.TimeBarContainer}>
186+
<div
187+
className={
188+
styles.TimeBarContainer +
189+
' ' +
190+
getClassNameForEnvironment(ioInfo.env)
191+
}>
185192
<div
186193
className={
187194
!isRejected ? styles.TimeBarSpan : styles.TimeBarSpanErrored
@@ -407,7 +414,10 @@ function SuspendedByGroup({
407414
<span className={styles.CollapsableHeaderTitle}>{pluralizedName}</span>
408415
<div className={styles.CollapsableHeaderFiller} />
409416
{isOpen ? null : (
410-
<div className={styles.TimeBarContainer}>
417+
<div
418+
className={
419+
styles.TimeBarContainer + ' ' + getClassNameForEnvironment(null)
420+
}>
411421
<div
412422
className={
413423
!isRejected ? styles.TimeBarSpan : styles.TimeBarSpanErrored
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.SuspenseEnvironmentDefault {
2+
--color-suspense: var(--color-suspense-default);
3+
--color-transition: var(--color-transition-default);
4+
}
5+
6+
.SuspenseEnvironmentServer {
7+
--color-suspense: var(--color-suspense-server);
8+
--color-transition: var(--color-transition-server);
9+
}
10+
11+
.SuspenseEnvironmentOther {
12+
--color-suspense: var(--color-suspense-other);
13+
--color-transition: var(--color-transition-other);
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import styles from './SuspenseEnvironmentColors.css';
11+
12+
export function getClassNameForEnvironment(environment: null | string): string {
13+
if (environment === null) {
14+
return styles.SuspenseEnvironmentDefault;
15+
}
16+
if (environment === 'Server') {
17+
return styles.SuspenseEnvironmentServer;
18+
}
19+
return styles.SuspenseEnvironmentOther;
20+
}

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseRects.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
SuspenseTreeStateContext,
3131
SuspenseTreeDispatcherContext,
3232
} from './SuspenseTreeContext';
33+
import {getClassNameForEnvironment} from './SuspenseEnvironmentColors.js';
3334

3435
function ScaledRect({
3536
className,
@@ -157,12 +158,25 @@ function SuspenseRects({
157158
hoveredTimelineIndex > -1 &&
158159
timeline[hoveredTimelineIndex].id === suspenseID;
159160

161+
let environment: null | string = null;
162+
for (let i = 0; i < timeline.length; i++) {
163+
const timelineStep = timeline[i];
164+
if (timelineStep.id === suspenseID) {
165+
environment = timelineStep.environment;
166+
break;
167+
}
168+
}
169+
160170
const boundingBox = getBoundingBox(suspense.rects);
161171

162172
return (
163173
<ScaledRect
164174
rect={boundingBox}
165-
className={styles.SuspenseRectsBoundary}
175+
className={
176+
styles.SuspenseRectsBoundary +
177+
' ' +
178+
getClassNameForEnvironment(environment)
179+
}
166180
visible={visible}
167181
selected={selected}
168182
suspended={suspense.isSuspended}
@@ -327,9 +341,8 @@ function SuspenseRectsContainer(): React$Node {
327341
const treeDispatch = useContext(TreeDispatcherContext);
328342
const suspenseTreeDispatch = useContext(SuspenseTreeDispatcherContext);
329343
// TODO: This relies on a full re-render of all children when the Suspense tree changes.
330-
const {roots, hoveredTimelineIndex, uniqueSuspendersOnly} = useContext(
331-
SuspenseTreeStateContext,
332-
);
344+
const {roots, timeline, hoveredTimelineIndex, uniqueSuspendersOnly} =
345+
useContext(SuspenseTreeStateContext);
333346

334347
// TODO: bbox does not consider uniqueSuspendersOnly filter
335348
const boundingBox = getDocumentBoundingRect(store, roots);
@@ -389,11 +402,16 @@ function SuspenseRectsContainer(): React$Node {
389402
}
390403
}
391404

405+
const rootEnvironment =
406+
timeline.length === 0 ? null : timeline[0].environment;
407+
392408
return (
393409
<div
394410
className={
395411
styles.SuspenseRectsContainer +
396-
(hasRootSuspenders ? ' ' + styles.SuspenseRectsRoot : '')
412+
(hasRootSuspenders ? ' ' + styles.SuspenseRectsRoot : '') +
413+
' ' +
414+
getClassNameForEnvironment(rootEnvironment)
397415
}
398416
onClick={handleClick}
399417
onDoubleClick={handleDoubleClick}

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseScrubber.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {useRef} from 'react';
1616

1717
import styles from './SuspenseScrubber.css';
1818

19+
import {getClassNameForEnvironment} from './SuspenseEnvironmentColors.js';
20+
1921
import Tooltip from '../Components/reach-ui/tooltip';
2022

2123
export default function SuspenseScrubber({
@@ -84,9 +86,10 @@ export default function SuspenseScrubber({
8486
styles.SuspenseScrubberBead +
8587
(index === min
8688
? // The first step in the timeline is always a Transition (Initial Paint).
87-
// TODO: Support multiple environments.
8889
' ' + styles.SuspenseScrubberBeadTransition
8990
: '') +
91+
' ' +
92+
getClassNameForEnvironment(environment) +
9093
(index <= value ? ' ' + styles.SuspenseScrubberBeadSelected : '')
9194
}
9295
/>

0 commit comments

Comments
 (0)