@devries-cameron20 / t3code Mirror · read-only / commits / 404c261e8a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 08:00 UTC

perf(web): the theme color picker compiles with the React Compiler (#20525)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 19:09 UTC 404c261e8a4b79a8d3259d3ac304b64c851428f7
2 files changed +33 -34
apps/web/reactCompiledFiles.ts
+1
@@ -92,4 +92,5 @@ export const REACT_COMPILED_FILES = [
92 "apps/web/src/components/settings/SnapShotSettings.tsx",
93 "apps/web/src/components/settings/ConnectionsSettings.tsx",
94 "apps/web/src/hooks/useResizeDrag.ts",
95 + "apps/web/src/components/settings/ThemeColorPicker.tsx",
96 ] as const;
apps/web/src/components/settings/ThemeColorPicker.tsx
+32 -34
@@ -1,4 +1,5 @@
1 -import { memo, useCallback, useEffect, useRef, useState } from "react";
1 +import { memo, useEffect, useEffectEvent, useRef, useState } from "react";
2 +import { useStableCallback } from "../../hooks/useStableCallback";
3 import { isThemeColor, themeColorToHex, type ThemeColorRole } from "../../themePalette";
4 import { cn } from "../../lib/utils";
5 import { hexToHsv, hsvToHex, type HsvColor } from "../../lib/color";
@@ -80,66 +81,63 @@ function ThemeColorPickerPanel({
81 const [hsv, setHsv] = useState(() => hexToHsv(normalizedValue));
82 const [hexDraft, setHexDraft] = useState(normalizedValue);
83 const [rgbDraft, setRgbDraft] = useState(() => themeRgbValue(normalizedValue));
83 - const isEditingTextRef = useRef(false);
84 + const [isEditingText, setIsEditingText] = useState(false);
85 + const [syncedValue, setSyncedValue] = useState(normalizedValue);
86 const currentColor = hsvToHex(hsv.h, hsv.s, hsv.v);
87 const currentRgb = themeRgbValue(currentColor);
88
87 - useEffect(() => {
89 + if (syncedValue !== normalizedValue) {
90 + setSyncedValue(normalizedValue);
91 // While a text field is focused, the incoming value may be the guided
92 // editor's readability-adjusted echo of what is being typed; rewriting the
93 // draft would fight the keystrokes. The swatch still tracks via hsv.
91 - if (!isEditingTextRef.current) {
94 + if (!isEditingText) {
95 setHexDraft(normalizedValue);
96 setRgbDraft(themeRgbValue(normalizedValue));
97 }
98 // Keep the current hue/saturation when the incoming value is just our own
99 // change echoed back; hex → HSV is lossy for greys, white, and black.
97 - setHsv((current) =>
98 - hsvToHex(current.h, current.s, current.v) === normalizedValue
99 - ? current
100 - : hexToHsv(normalizedValue),
101 - );
102 - }, [normalizedValue]);
100 + if (currentColor !== normalizedValue) setHsv(hexToHsv(normalizedValue));
101 + }
102
103 // Local state updates immediately for a smooth thumb; the parent commit
104 // (which can regenerate a whole guided palette) is batched to one call per
105 // animation frame.
107 - const onChangeRef = useRef(onChange);
108 - onChangeRef.current = onChange;
106 + const commitColor = useStableCallback(onChange);
107 const pendingCommitRef = useRef<string | null>(null);
108 const commitFrameRef = useRef<number | null>(null);
109 // The final drag frame must not be lost when the popover closes or the
110 // pointer lifts before the animation frame fires.
113 - const flushPendingCommit = useCallback(() => {
111 + const flushPendingCommit = () => {
112 if (commitFrameRef.current !== null) {
113 cancelAnimationFrame(commitFrameRef.current);
114 commitFrameRef.current = null;
115 }
116 const pending = pendingCommitRef.current;
117 pendingCommitRef.current = null;
120 - if (pending !== null) onChangeRef.current(pending);
121 - }, []);
122 - useEffect(() => () => flushPendingCommit(), [flushPendingCommit]);
123 - const scheduleCommit = useCallback((color: string) => {
118 + if (pending !== null) commitColor(pending);
119 + };
120 + // Flush only on unmount; rerunning this cleanup mid-drag would commit early.
121 + const flushOnUnmount = useEffectEvent(() => flushPendingCommit());
122 + useEffect(() => () => flushOnUnmount(), []);
123 + const scheduleCommit = (color: string) => {
124 pendingCommitRef.current = color;
125 - commitFrameRef.current ??= requestAnimationFrame(() => {
125 + if (commitFrameRef.current !== null) return;
126 + commitFrameRef.current = requestAnimationFrame(() => {
127 commitFrameRef.current = null;
128 const pending = pendingCommitRef.current;
129 pendingCommitRef.current = null;
129 - if (pending !== null) onChangeRef.current(pending);
130 + if (pending !== null) commitColor(pending);
131 });
131 - }, []);
132 + };
133
133 - const commitHsv = useCallback(
134 - (nextHsv: HsvColor) => {
135 - setHsv(nextHsv);
136 - const nextColor = hsvToHex(nextHsv.h, nextHsv.s, nextHsv.v);
137 - setHexDraft(nextColor);
138 - setRgbDraft(themeRgbValue(nextColor));
139 - scheduleCommit(nextColor + alphaSuffix);
140 - },
141 - [alphaSuffix, scheduleCommit],
142 - );
134 + const commitHsv = (nextHsv: HsvColor) => {
135 + setHsv(nextHsv);
136 + const nextColor = hsvToHex(nextHsv.h, nextHsv.s, nextHsv.v);
137 + setHexDraft(nextColor);
138 + setRgbDraft(themeRgbValue(nextColor));
139 + scheduleCommit(nextColor + alphaSuffix);
140 + };
141
142 const handleHexChange = (nextValue: string) => {
143 setHexDraft(nextValue);
@@ -198,13 +196,13 @@ function ThemeColorPickerPanel({
196 aria-label={`${label} picker hex value`}
197 className="h-8 min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none"
198 onBlur={() => {
201 - isEditingTextRef.current = false;
199 + setIsEditingText(false);
200 setHexDraft(currentColor);
201 setRgbDraft(currentRgb);
202 }}
203 onChange={(event) => handleHexChange(event.currentTarget.value)}
204 onFocus={() => {
207 - isEditingTextRef.current = true;
205 + setIsEditingText(true);
206 }}
207 spellCheck={false}
208 value={hexDraft}
@@ -220,13 +218,13 @@ function ThemeColorPickerPanel({
218 aria-label={`${label} picker RGB value`}
219 className="h-8 min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none"
220 onBlur={() => {
223 - isEditingTextRef.current = false;
221 + setIsEditingText(false);
222 setHexDraft(currentColor);
223 setRgbDraft(currentRgb);
224 }}
225 onChange={(event) => handleRgbChange(event.currentTarget.value)}
226 onFocus={() => {
229 - isEditingTextRef.current = true;
227 + setIsEditingText(true);
228 }}
229 spellCheck={false}
230 value={rgbDraft}