Skip to content

Commit 6045239

Browse files
committed
Extract shared colorblind palette and fix DiffStatLabel memoization
Move COLORBLIND_DIFF_STYLES to diffRendering.ts so the palette is defined once instead of duplicated across three files. Convert DiffStatLabel to accept colorblindStyle as a prop instead of calling useSettings/useTheme internally, preserving its memo() contract. Thread the prop from ChatView through MessagesTimeline and ChangedFilesTree.
1 parent 0e999b5 commit 6045239

7 files changed

Lines changed: 52 additions & 55 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } fr
2727
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2828
import { useDebouncedValue } from "@tanstack/react-pacer";
2929
import { useNavigate, useSearch } from "@tanstack/react-router";
30+
import { COLORBLIND_DIFF_STYLES } from "~/lib/diffRendering";
3031
import { gitBranchesQueryOptions, gitCreateWorktreeMutationOptions } from "~/lib/gitReactQuery";
3132
import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery";
3233
import { serverConfigQueryOptions, serverQueryKeys } from "~/lib/serverReactQuery";
@@ -263,6 +264,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
263264
select: (params) => parseDiffRouteSearch(params),
264265
});
265266
const { resolvedTheme } = useTheme();
267+
const colorblindStyle = settings.colorblindMode ? COLORBLIND_DIFF_STYLES[resolvedTheme] : null;
266268
const queryClient = useQueryClient();
267269
const createWorktreeMutation = useMutation(gitCreateWorktreeMutationOptions({ queryClient }));
268270
const composerDraft = useComposerThreadDraft(threadId);
@@ -3655,6 +3657,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
36553657
onImageExpand={onExpandTimelineImage}
36563658
markdownCwd={gitCwd ?? undefined}
36573659
resolvedTheme={resolvedTheme}
3660+
colorblindStyle={colorblindStyle}
36583661
timestampFormat={timestampFormat}
36593662
workspaceRoot={activeProject?.cwd ?? undefined}
36603663
/>

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ import { readNativeApi } from "../nativeApi";
2626
import { resolvePathLinkTarget } from "../terminal-links";
2727
import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch";
2828
import { useTheme } from "../hooks/useTheme";
29-
import { buildPatchCacheKey } from "../lib/diffRendering";
30-
import { resolveDiffThemeName } from "../lib/diffRendering";
29+
import {
30+
buildPatchCacheKey,
31+
COLORBLIND_DIFF_STYLES,
32+
resolveDiffThemeName,
33+
} from "../lib/diffRendering";
3134
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
3235
import { useStore } from "../store";
3336
import { useSettings } from "../hooks/useSettings";
@@ -38,26 +41,10 @@ import { ToggleGroup, Toggle } from "./ui/toggle-group";
3841
type DiffRenderMode = "stacked" | "split";
3942
type DiffThemeType = "light" | "dark";
4043

41-
// GitHub Primer colorblind palette (protanopia/deuteranopia).
42-
// Source: @primer/primitives diffBlob tokens — the industry standard.
43-
// Light: addition #0969da (blue), deletion #bc4c00 (orange)
44-
// Dark: addition #388bfd (blue), deletion #db6d28 (orange)
45-
const CB_ADDITION_LIGHT = "#0969da";
46-
const CB_ADDITION_DARK = "#388bfd";
47-
const CB_DELETION_LIGHT = "#bc4c00";
48-
const CB_DELETION_DARK = "#db6d28";
49-
5044
function buildDiffPanelCss(colorblind: boolean, theme: "light" | "dark"): string {
51-
const addition = colorblind
52-
? theme === "dark"
53-
? CB_ADDITION_DARK
54-
: CB_ADDITION_LIGHT
55-
: "var(--success)";
56-
const deletion = colorblind
57-
? theme === "dark"
58-
? CB_DELETION_DARK
59-
: CB_DELETION_LIGHT
60-
: "var(--destructive)";
45+
const cb = colorblind ? COLORBLIND_DIFF_STYLES[theme] : null;
46+
const addition = cb ? cb.addition.color : "var(--success)";
47+
const deletion = cb ? cb.deletion.color : "var(--destructive)";
6148

6249
return `
6350
[data-diffs-header],

‎apps/web/src/components/GitActionsControl.tsx‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,7 @@ import { resolvePathLinkTarget } from "~/terminal-links";
5252
import { readNativeApi } from "~/nativeApi";
5353
import { useSettings } from "~/hooks/useSettings";
5454
import { useTheme } from "~/hooks/useTheme";
55-
56-
// GitHub Primer colorblind palette (protanopia/deuteranopia).
57-
const CB_STYLES = {
58-
light: {
59-
addition: { color: "#0969da" },
60-
deletion: { color: "#bc4c00" },
61-
},
62-
dark: {
63-
addition: { color: "#388bfd" },
64-
deletion: { color: "#db6d28" },
65-
},
66-
} as const;
55+
import { COLORBLIND_DIFF_STYLES } from "~/lib/diffRendering";
6756

6857
interface GitActionsControlProps {
6958
gitCwd: string | null;
@@ -220,7 +209,7 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
220209
export default function GitActionsControl({ gitCwd, activeThreadId }: GitActionsControlProps) {
221210
const { colorblindMode } = useSettings();
222211
const { resolvedTheme } = useTheme();
223-
const cb = colorblindMode ? CB_STYLES[resolvedTheme] : null;
212+
const cb = colorblindMode ? COLORBLIND_DIFF_STYLES[resolvedTheme] : null;
224213
const threadToastData = useMemo(
225214
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
226215
[activeThreadId],

‎apps/web/src/components/chat/ChangedFilesTree.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import { ChevronRightIcon, FolderIcon, FolderClosedIcon } from "lucide-react";
66
import { cn } from "~/lib/utils";
77
import { DiffStatLabel, hasNonZeroStat } from "./DiffStatLabel";
88
import { VscodeEntryIcon } from "./VscodeEntryIcon";
9+
import type { ColorblindDiffStyle } from "~/lib/diffRendering";
910

1011
export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
1112
turnId: TurnId;
1213
files: ReadonlyArray<TurnDiffFileChange>;
1314
allDirectoriesExpanded: boolean;
1415
resolvedTheme: "light" | "dark";
16+
colorblindStyle?: ColorblindDiffStyle | null | undefined;
1517
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
1618
}) {
17-
const { files, allDirectoriesExpanded, onOpenTurnDiff, resolvedTheme, turnId } = props;
19+
const { files, allDirectoriesExpanded, onOpenTurnDiff, resolvedTheme, colorblindStyle, turnId } =
20+
props;
1821
const treeNodes = useMemo(() => buildTurnDiffTree(files), [files]);
1922
const directoryPathsKey = useMemo(
2023
() => collectDirectoryPaths(treeNodes).join("\u0000"),
@@ -71,7 +74,11 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
7174
</span>
7275
{hasNonZeroStat(node.stat) && (
7376
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
74-
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
77+
<DiffStatLabel
78+
additions={node.stat.additions}
79+
deletions={node.stat.deletions}
80+
colorblindStyle={colorblindStyle}
81+
/>
7582
</span>
7683
)}
7784
</button>
@@ -104,7 +111,11 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
104111
</span>
105112
{node.stat && (
106113
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
107-
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
114+
<DiffStatLabel
115+
additions={node.stat.additions}
116+
deletions={node.stat.deletions}
117+
colorblindStyle={colorblindStyle}
118+
/>
108119
</span>
109120
)}
110121
</button>

‎apps/web/src/components/chat/DiffStatLabel.tsx‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
import { memo } from "react";
2-
import { useSettings } from "~/hooks/useSettings";
3-
import { useTheme } from "~/hooks/useTheme";
2+
import type { ColorblindDiffStyle } from "~/lib/diffRendering";
43

54
export function hasNonZeroStat(stat: { additions: number; deletions: number }): boolean {
65
return stat.additions > 0 || stat.deletions > 0;
76
}
87

9-
// GitHub Primer colorblind palette (protanopia/deuteranopia).
10-
const CB_STYLES = {
11-
light: {
12-
addition: { color: "#0969da" },
13-
deletion: { color: "#bc4c00" },
14-
},
15-
dark: {
16-
addition: { color: "#388bfd" },
17-
deletion: { color: "#db6d28" },
18-
},
19-
} as const;
20-
218
export const DiffStatLabel = memo(function DiffStatLabel(props: {
229
additions: number;
2310
deletions: number;
2411
showParentheses?: boolean;
12+
colorblindStyle?: ColorblindDiffStyle | null | undefined;
2513
}) {
26-
const { additions, deletions, showParentheses = false } = props;
27-
const { colorblindMode } = useSettings();
28-
const { resolvedTheme } = useTheme();
29-
const cb = colorblindMode ? CB_STYLES[resolvedTheme] : null;
14+
const { additions, deletions, showParentheses = false, colorblindStyle: cb } = props;
3015

3116
return (
3217
<>

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { buildExpandedImagePreview, ExpandedImagePreview } from "./ExpandedImage
4040
import { ProposedPlanCard } from "./ProposedPlanCard";
4141
import { ChangedFilesTree } from "./ChangedFilesTree";
4242
import { DiffStatLabel, hasNonZeroStat } from "./DiffStatLabel";
43+
import type { ColorblindDiffStyle } from "~/lib/diffRendering";
4344
import { MessageCopyButton } from "./MessageCopyButton";
4445
import { computeMessageDurationStart, normalizeCompactToolLabel } from "./MessagesTimeline.logic";
4546
import { TerminalContextInlineChip } from "./TerminalContextInlineChip";
@@ -79,6 +80,7 @@ interface MessagesTimelineProps {
7980
onImageExpand: (preview: ExpandedImagePreview) => void;
8081
markdownCwd: string | undefined;
8182
resolvedTheme: "light" | "dark";
83+
colorblindStyle?: ColorblindDiffStyle | null | undefined;
8284
timestampFormat: TimestampFormat;
8385
workspaceRoot: string | undefined;
8486
}
@@ -103,6 +105,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
103105
onImageExpand,
104106
markdownCwd,
105107
resolvedTheme,
108+
colorblindStyle,
106109
timestampFormat,
107110
workspaceRoot,
108111
}: MessagesTimelineProps) {
@@ -474,6 +477,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
474477
<DiffStatLabel
475478
additions={summaryStat.additions}
476479
deletions={summaryStat.deletions}
480+
colorblindStyle={colorblindStyle}
477481
/>
478482
</>
479483
)}
@@ -505,6 +509,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
505509
files={checkpointFiles}
506510
allDirectoriesExpanded={allDirectoriesExpanded}
507511
resolvedTheme={resolvedTheme}
512+
colorblindStyle={colorblindStyle}
508513
onOpenTurnDiff={onOpenTurnDiff}
509514
/>
510515
</div>

‎apps/web/src/lib/diffRendering.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
// GitHub Primer colorblind palette (protanopia/deuteranopia).
2+
// Source: @primer/primitives diffBlob tokens.
3+
// Light: addition #0969da (blue), deletion #bc4c00 (orange)
4+
// Dark: addition #388bfd (blue), deletion #db6d28 (orange)
5+
export const COLORBLIND_DIFF_STYLES = {
6+
light: {
7+
addition: { color: "#0969da" } as const,
8+
deletion: { color: "#bc4c00" } as const,
9+
},
10+
dark: {
11+
addition: { color: "#388bfd" } as const,
12+
deletion: { color: "#db6d28" } as const,
13+
},
14+
} as const;
15+
16+
export type ColorblindDiffStyle = (typeof COLORBLIND_DIFF_STYLES)["light" | "dark"];
17+
118
export const DIFF_THEME_NAMES = {
219
light: "pierre-light",
320
dark: "pierre-dark",

0 commit comments

Comments
 (0)