@devries-cameron20 / t3code-1 / commits / 6a71716edb
Fork 0

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

perf(web): theme import dialog compile with the React Compiler (#20513)

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

Julius Marminge committed Oct 16, 2026 at 18:53 UTC 6a71716edbc52274369b987cda475f7e9f094329
2 files changed +137 -140
apps/web/reactCompiledFiles.ts
+1
@@ -88,4 +88,5 @@ export const REACT_COMPILED_FILES = [
88 "apps/web/src/components/settings/AcpSessionManagementSection.tsx",
89 "apps/web/src/components/settings/CaptureShortcutConfig.tsx",
90 "apps/web/src/components/settings/IntegrationsSettings.tsx",
91 + "apps/web/src/components/settings/ThemeImportDialog.tsx",
92 ] as const;
apps/web/src/components/settings/ThemeImportDialog.tsx
+136 -140
@@ -1,6 +1,7 @@
1 import { DownloadIcon, PlusIcon } from "lucide-react";
2 import type { ChangeEvent, DragEvent, UIEvent } from "react";
3 -import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3 +import { settlePromise } from "@t3tools/client-runtime/state/runtime";
4 +import { useEffect, useRef, useState } from "react";
5 import { cn } from "../../lib/utils";
6 import {
7 getCustomThemes,
@@ -96,17 +97,14 @@ function ThemeJsonEditor({
97 }) {
98 const highlightRef = useRef<HTMLPreElement>(null);
99 const isPlainText = value.length > MAX_HIGHLIGHTED_JSON_LENGTH;
99 - const highlightedJson = useMemo(
100 - () => (value.length > MAX_HIGHLIGHTED_JSON_LENGTH ? "" : highlightJson(value)),
101 - [value],
102 - );
100 + const highlightedJson = isPlainText ? "" : highlightJson(value);
101
104 - const syncScroll = useCallback((event: UIEvent<HTMLTextAreaElement>) => {
102 + const syncScroll = (event: UIEvent<HTMLTextAreaElement>) => {
103 const highlightElement = highlightRef.current;
104 if (!highlightElement) return;
105 highlightElement.scrollTop = event.currentTarget.scrollTop;
106 highlightElement.scrollLeft = event.currentTarget.scrollLeft;
109 - }, []);
107 + };
108
109 return (
110 <div className="relative overflow-hidden rounded-xl border border-input bg-background shadow-xs/5 focus-within:border-ring focus-within:ring-3 focus-within:ring-inset focus-within:ring-ring/24">
@@ -160,18 +158,28 @@ export function ThemeImportDialog({
158 const [conflicts, setConflicts] = useState<ReadonlyArray<ThemeDefinition> | null>(null);
159 const importRequestRef = useRef(0);
160
163 - useEffect(() => {
164 - importRequestRef.current += 1;
161 + const [renderedOpen, setRenderedOpen] = useState(open);
162 + if (renderedOpen !== open) {
163 + setRenderedOpen(open);
164 setIsDropTarget(false);
165 + if (open) {
166 + setJson("");
167 + setFileName(null);
168 + setError(null);
169 + setIsReading(false);
170 + setConflicts(null);
171 + }
172 + }
173 + // Opening or closing drops any read still in flight.
174 + useEffect(() => {
175 if (!open) return;
167 - setJson("");
168 - setFileName(null);
169 - setError(null);
170 - setIsReading(false);
171 - setConflicts(null);
176 + importRequestRef.current += 1;
177 + return () => {
178 + importRequestRef.current += 1;
179 + };
180 }, [open]);
181
174 - const readThemeFile = useCallback(async (file: ImportableThemeFile) => {
182 + const readThemeFile = async (file: ImportableThemeFile) => {
183 const oversized = describeOversizedThemeFile(file.size);
184 if (oversized) {
185 setError(oversized);
@@ -180,86 +188,83 @@ export function ThemeImportDialog({
188
189 const requestId = ++importRequestRef.current;
190 setIsReading(true);
183 - try {
184 - const fileText = await file.text();
185 - if (requestId !== importRequestRef.current) return;
186 - setJson(fileText);
187 - setFileName(file.name);
188 - setError(null);
189 - } catch {
190 - if (requestId !== importRequestRef.current) return;
191 + const fileText = await settlePromise(() => file.text());
192 + if (requestId !== importRequestRef.current) return;
193 + setIsReading(false);
194 + if (fileText._tag === "Failure") {
195 setError("Could not read that file. Paste the JSON below instead.");
192 - } finally {
193 - if (requestId === importRequestRef.current) setIsReading(false);
196 + return;
197 }
195 - }, []);
198 + setJson(fileText.value);
199 + setFileName(file.name);
200 + setError(null);
201 + };
202
197 - const readThemeBatch = useCallback(
198 - async (files: ReadonlyArray<ImportableThemeFile>) => {
199 - const requestId = ++importRequestRef.current;
200 - setIsReading(true);
201 - const failures: string[] = [];
202 - const parsed: Array<{ theme: ThemeDefinition; sourceName: string }> = [];
203 + const readThemeBatch = (files: ReadonlyArray<ImportableThemeFile>) => {
204 + const requestId = ++importRequestRef.current;
205 + setIsReading(true);
206 + return installThemeBatch(files, requestId).finally(() => {
207 + if (requestId === importRequestRef.current) setIsReading(false);
208 + });
209 + };
210 +
211 + const installThemeBatch = async (
212 + files: ReadonlyArray<ImportableThemeFile>,
213 + requestId: number,
214 + ) => {
215 + const failures: string[] = [];
216 + const parsed: Array<{ theme: ThemeDefinition; sourceName: string }> = [];
217 + for (const file of files) {
218 + const oversized = describeOversizedThemeFile(file.size);
219 + if (oversized) {
220 + failures.push(`${file.name}: too large`);
221 + continue;
222 + }
223 try {
204 - for (const file of files) {
205 - const oversized = describeOversizedThemeFile(file.size);
206 - if (oversized) {
207 - failures.push(`${file.name}: too large`);
208 - continue;
209 - }
210 - try {
211 - const value: unknown = JSON.parse(await file.text());
212 - parsed.push({
213 - sourceName: file.name,
214 - theme: isVsCodeThemeFile(value) ? parseVsCodeThemeFile(value) : parseThemeFile(value),
215 - });
216 - } catch (cause) {
217 - failures.push(
218 - `${file.name}: ${cause instanceof Error ? cause.message : "not a theme file"}`,
219 - );
220 - }
221 - }
222 - if (requestId !== importRequestRef.current) return;
223 - const installed: ThemeDefinition[] = [];
224 - const conflicting: ThemeDefinition[] = [];
225 - for (const theme of pairVsCodeThemes(resolveThemeLabelCollisions(parsed))) {
226 - if (getCustomThemes().some((existing) => existing.id === theme.id)) {
227 - conflicting.push(theme);
228 - continue;
229 - }
230 - try {
231 - installed.push(installCustomTheme(theme));
232 - } catch (cause) {
233 - failures.push(
234 - `${theme.label}: ${cause instanceof Error ? cause.message : "could not install"}`,
235 - );
236 - }
237 - }
238 - if (installed.length > 0) onImportedMany(installed, { updated: false });
239 - if (failures.length > 0) {
240 - setError(failures.join(" — "));
241 - } else if (conflicting.length > 0) {
242 - setConflicts(conflicting);
243 - } else if (installed.length > 0) {
244 - onOpenChange(false);
245 - }
246 - } finally {
247 - if (requestId === importRequestRef.current) setIsReading(false);
224 + const value: unknown = JSON.parse(await file.text());
225 + parsed.push({
226 + sourceName: file.name,
227 + theme: isVsCodeThemeFile(value) ? parseVsCodeThemeFile(value) : parseThemeFile(value),
228 + });
229 + } catch (cause) {
230 + failures.push(
231 + `${file.name}: ${cause instanceof Error ? cause.message : "not a theme file"}`,
232 + );
233 }
249 - },
250 - [onImportedMany, onOpenChange],
251 - );
234 + }
235 + if (requestId !== importRequestRef.current) return;
236 + const installed: ThemeDefinition[] = [];
237 + const conflicting: ThemeDefinition[] = [];
238 + for (const theme of pairVsCodeThemes(resolveThemeLabelCollisions(parsed))) {
239 + if (getCustomThemes().some((existing) => existing.id === theme.id)) {
240 + conflicting.push(theme);
241 + continue;
242 + }
243 + try {
244 + installed.push(installCustomTheme(theme));
245 + } catch (cause) {
246 + failures.push(
247 + `${theme.label}: ${cause instanceof Error ? cause.message : "could not install"}`,
248 + );
249 + }
250 + }
251 + if (installed.length > 0) onImportedMany(installed, { updated: false });
252 + if (failures.length > 0) {
253 + setError(failures.join(" — "));
254 + } else if (conflicting.length > 0) {
255 + setConflicts(conflicting);
256 + } else if (installed.length > 0) {
257 + onOpenChange(false);
258 + }
259 + };
260
253 - const readThemeFiles = useCallback(
254 - (files: ReadonlyArray<ImportableThemeFile>) => {
255 - if (files.length === 0) return;
256 - if (files.length === 1) void readThemeFile(files[0]!);
257 - else void readThemeBatch(files);
258 - },
259 - [readThemeBatch, readThemeFile],
260 - );
261 + const readThemeFiles = (files: ReadonlyArray<ImportableThemeFile>) => {
262 + if (files.length === 0) return;
263 + if (files.length === 1) void readThemeFile(files[0]!);
264 + else void readThemeBatch(files);
265 + };
266
262 - const openFilePicker = useCallback(() => {
267 + const openFilePicker = () => {
268 const bridge = window.desktopBridge;
269 if (bridge?.pickThemeFiles) {
270 void bridge.pickThemeFiles().then((picked) => {
@@ -275,25 +280,19 @@ export function ThemeImportDialog({
280 return;
281 }
282 fileInputRef.current?.click();
278 - }, [readThemeFiles]);
283 + };
284
280 - const handleFileChange = useCallback(
281 - (event: ChangeEvent<HTMLInputElement>) => {
282 - const files = [...(event.currentTarget.files ?? [])];
283 - event.currentTarget.value = "";
284 - readThemeFiles(files);
285 - },
286 - [readThemeFiles],
287 - );
285 + const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
286 + const files = [...(event.currentTarget.files ?? [])];
287 + event.currentTarget.value = "";
288 + readThemeFiles(files);
289 + };
290
289 - const handleDrop = useCallback(
290 - (event: DragEvent<HTMLDivElement>) => {
291 - event.preventDefault();
292 - setIsDropTarget(false);
293 - readThemeFiles([...event.dataTransfer.files]);
294 - },
295 - [readThemeFiles],
296 - );
291 + const handleDrop = (event: DragEvent<HTMLDivElement>) => {
292 + event.preventDefault();
293 + setIsDropTarget(false);
294 + readThemeFiles([...event.dataTransfer.files]);
295 + };
296
297 const versionedCopy = (
298 theme: ThemeDefinition,
@@ -325,42 +324,39 @@ export function ThemeImportDialog({
324 throw new Error(`Too many copies of "${theme.label}".`);
325 };
326
328 - const resolveConflicts = useCallback(
329 - (mode: "update" | "copy") => {
330 - if (!conflicts) return;
331 - const resolved: ThemeDefinition[] = [];
332 - const failures: string[] = [];
333 - const preferredName =
334 - conflicts.length === 1 && fileName
335 - ? humanizeThemeName(fileName.replace(/\.[^.]+$/, ""))
336 - : null;
337 - for (const theme of conflicts) {
338 - try {
339 - const existingTheme =
340 - mode === "update"
341 - ? getCustomThemes().find((candidate) => candidate.id === theme.id)
342 - : undefined;
343 - const themeToUpdate = existingTheme?.collection
344 - ? { ...theme, collection: existingTheme.collection }
345 - : theme;
346 - resolved.push(
347 - mode === "update"
348 - ? updateCustomTheme(themeToUpdate)
349 - : installCustomTheme(versionedCopy(theme, preferredName)),
350 - );
351 - } catch (cause) {
352 - failures.push(`${theme.label}: ${cause instanceof Error ? cause.message : "failed"}`);
353 - }
327 + const resolveConflicts = (mode: "update" | "copy") => {
328 + if (!conflicts) return;
329 + const resolved: ThemeDefinition[] = [];
330 + const failures: string[] = [];
331 + const preferredName =
332 + conflicts.length === 1 && fileName
333 + ? humanizeThemeName(fileName.replace(/\.[^.]+$/, ""))
334 + : null;
335 + for (const theme of conflicts) {
336 + try {
337 + const existingTheme =
338 + mode === "update"
339 + ? getCustomThemes().find((candidate) => candidate.id === theme.id)
340 + : undefined;
341 + const themeToUpdate = existingTheme?.collection
342 + ? { ...theme, collection: existingTheme.collection }
343 + : theme;
344 + resolved.push(
345 + mode === "update"
346 + ? updateCustomTheme(themeToUpdate)
347 + : installCustomTheme(versionedCopy(theme, preferredName)),
348 + );
349 + } catch (cause) {
350 + failures.push(`${theme.label}: ${cause instanceof Error ? cause.message : "failed"}`);
351 }
355 - if (resolved.length > 0) onImportedMany(resolved, { updated: mode === "update" });
356 - setConflicts(null);
357 - if (failures.length > 0) setError(failures.join(" — "));
358 - else onOpenChange(false);
359 - },
360 - [conflicts, fileName, onImportedMany, onOpenChange],
361 - );
352 + }
353 + if (resolved.length > 0) onImportedMany(resolved, { updated: mode === "update" });
354 + setConflicts(null);
355 + if (failures.length > 0) setError(failures.join(" — "));
356 + else onOpenChange(false);
357 + };
358
363 - const handleSubmit = useCallback(() => {
359 + const handleSubmit = () => {
360 const oversized = describeOversizedThemeFile(json.length);
361 if (oversized) {
362 setError(oversized);
@@ -388,7 +384,7 @@ export function ThemeImportDialog({
384 } catch (cause) {
385 setError(cause instanceof Error ? cause.message : "That theme file is invalid.");
386 }
391 - }, [json, onImported, onOpenChange]);
387 + };
388
389 return (
390 <Dialog