Skip to content

Commit 5e5ffb8

Browse files
perf(web): the theme library compiles with the React Compiler
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a702563 commit 5e5ffb8

1 file changed

Lines changed: 40 additions & 64 deletions

File tree

‎apps/web/src/components/settings/ThemeSettings.tsx‎

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Trash2Icon,
1010
UploadIcon,
1111
} from "lucide-react";
12-
import { useCallback, useEffect, useState, type ReactElement } from "react";
12+
import { useState, type ReactElement } from "react";
1313
import { useEnvironmentThemeDefinitions } from "../../hooks/useEnvironmentTheme";
1414
import { readThemeHalvesRaw } from "../../hooks/useTheme";
1515
import { cn } from "../../lib/utils";
@@ -442,9 +442,7 @@ function CustomThemeCollectionCard({
442442
const safeIndex = Math.min(variantIndex, themes.length - 1);
443443
const theme = themes[safeIndex];
444444

445-
useEffect(() => {
446-
if (variantIndex !== safeIndex) setVariantIndex(safeIndex);
447-
}, [safeIndex, variantIndex]);
445+
if (variantIndex !== safeIndex) setVariantIndex(safeIndex);
448446

449447
if (!theme) return null;
450448
const collectionLabel = theme.collection?.label ?? theme.label;
@@ -537,45 +535,42 @@ export function ThemeLibrary({
537535
const removeDialogCollectionLabel =
538536
removeDialogTheme?.collection?.label ?? removeDialogTheme?.label;
539537

540-
const notifyThemeSaveFailure = useCallback(() => {
538+
const notifyThemeSaveFailure = () => {
541539
toastManager.add(
542540
stackedThreadToast({
543541
type: "error",
544542
title: "Couldn’t save theme selection",
545543
description: "Try again.",
546544
}),
547545
);
548-
}, []);
546+
};
549547

550-
const notifyThemeRemovalFailure = useCallback(() => {
548+
const notifyThemeRemovalFailure = () => {
551549
toastManager.add(
552550
stackedThreadToast({
553551
type: "error",
554552
title: "Couldn’t remove theme",
555553
description: "Try again.",
556554
}),
557555
);
558-
}, []);
556+
};
559557

560-
const persistTheme = useCallback(
561-
(nextTheme: string) => {
562-
const didSave = setTheme(nextTheme);
563-
if (!didSave) notifyThemeSaveFailure();
564-
return didSave;
565-
},
566-
[notifyThemeSaveFailure, setTheme],
567-
);
558+
const persistTheme = (nextTheme: string) => {
559+
const didSave = setTheme(nextTheme);
560+
if (!didSave) notifyThemeSaveFailure();
561+
return didSave;
562+
};
568563

569-
const handleRemoveTheme = useCallback(
570-
(customTheme: ThemeDefinition, collectionThemes: ReadonlyArray<ThemeDefinition>) => {
571-
setThemeRemovalTarget({ theme: customTheme, collectionThemes });
572-
setThemeIdsToRemove(collectionThemes.length > 1 ? [] : [customTheme.id]);
573-
setIsThemeRemovalOpen(true);
574-
},
575-
[],
576-
);
564+
const handleRemoveTheme = (
565+
customTheme: ThemeDefinition,
566+
collectionThemes: ReadonlyArray<ThemeDefinition>,
567+
) => {
568+
setThemeRemovalTarget({ theme: customTheme, collectionThemes });
569+
setThemeIdsToRemove(collectionThemes.length > 1 ? [] : [customTheme.id]);
570+
setIsThemeRemovalOpen(true);
571+
};
577572

578-
const handleConfirmRemoveTheme = useCallback(() => {
573+
const handleConfirmRemoveTheme = () => {
579574
if (!themeRemovalTarget) return;
580575
const removedIds = new Set(themeIdsToRemove);
581576
if (removedIds.size === 0) return;
@@ -603,52 +598,33 @@ export function ThemeLibrary({
603598
return;
604599
}
605600
setIsThemeRemovalOpen(false);
606-
}, [
607-
appearanceMode,
608-
notifyThemeRemovalFailure,
609-
persistTheme,
610-
setThemeHalf,
611-
theme,
612-
themeIdsToRemove,
613-
themeRemovalTarget,
614-
]);
601+
};
615602

616603
const baseCardId = getThemeDefinition(theme)?.id ?? null;
617604
const lightOwner = themeHalves?.light ?? baseCardId;
618605
const darkOwner = themeHalves?.dark ?? baseCardId;
619606

620-
const assignHalf = useCallback(
621-
(appearance: ThemeAppearance, cardId: string | null) => {
622-
const otherAppearance = appearance === "light" ? "dark" : "light";
623-
// Picking the default over a themed base cannot be stored as a half:
624-
// the base would still own that appearance. Convert the base into an
625-
// explicit half on the other side so this side falls back to default.
626-
if (cardId === null && baseCardId !== null) {
627-
// Read raw, before persistTheme clears the mix: the other half may
628-
// name a published theme that has not streamed in yet, and falling
629-
// back to the base would silently rewrite it.
630-
const otherOwner = readThemeHalvesRaw()[otherAppearance] ?? baseCardId;
631-
if (!persistTheme(appearanceMode === "system" ? "system" : appearanceMode)) return;
632-
if (!setThemeHalf(otherAppearance, otherOwner)) {
633-
setTheme(theme);
634-
notifyThemeSaveFailure();
635-
}
636-
return;
637-
}
638-
if (!setThemeHalf(appearance, cardId)) {
607+
const assignHalf = (appearance: ThemeAppearance, cardId: string | null) => {
608+
const otherAppearance = appearance === "light" ? "dark" : "light";
609+
// Picking the default over a themed base cannot be stored as a half:
610+
// the base would still own that appearance. Convert the base into an
611+
// explicit half on the other side so this side falls back to default.
612+
if (cardId === null && baseCardId !== null) {
613+
// Read raw, before persistTheme clears the mix: the other half may
614+
// name a published theme that has not streamed in yet, and falling
615+
// back to the base would silently rewrite it.
616+
const otherOwner = readThemeHalvesRaw()[otherAppearance] ?? baseCardId;
617+
if (!persistTheme(appearanceMode === "system" ? "system" : appearanceMode)) return;
618+
if (!setThemeHalf(otherAppearance, otherOwner)) {
619+
setTheme(theme);
639620
notifyThemeSaveFailure();
640621
}
641-
},
642-
[
643-
appearanceMode,
644-
baseCardId,
645-
notifyThemeSaveFailure,
646-
persistTheme,
647-
setTheme,
648-
setThemeHalf,
649-
theme,
650-
],
651-
);
622+
return;
623+
}
624+
if (!setThemeHalf(appearance, cardId)) {
625+
notifyThemeSaveFailure();
626+
}
627+
};
652628

653629
const activeThemeForAppearance =
654630
getThemeDefinition((initialAppearance === "light" ? lightOwner : darkOwner) ?? "") ?? null;

0 commit comments

Comments
 (0)