Skip to content

Commit 57ebd82

Browse files
committed
Fix appearance/settings bugs: remove harmful effect cleanup, fix theme migration ordering, remove redundant reset call
- Remove useEffect cleanup that called removeThemeTokens() in useAppearance, which would delete the shared global <style> element when any component using the hook unmounted, breaking themes on navigation. - Move t3code:theme localStorage migration before the OLD_SETTINGS_KEY guard in migrateLocalSettingsToServer, so users who already migrated old settings (or never had them) still get their theme preference migrated. - Remove redundant updateSettings() call before resetSettings() in useSettingsRestore, since resetSettings already applies all defaults including appearance values.
1 parent f4ab7eb commit 57ebd82

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

apps/web/src/components/settings/SettingsPanels.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function AboutVersionSection() {
424424

425425
export function useSettingsRestore(onRestored?: () => void) {
426426
const settings = useSettings();
427-
const { updateSettings, resetSettings } = useUpdateSettings();
427+
const { resetSettings } = useUpdateSettings();
428428

429429
const isGitWritingModelDirty = !Equal.equals(
430430
settings.textGenerationModelSelection ?? null,
@@ -487,10 +487,9 @@ export function useSettingsRestore(onRestored?: () => void) {
487487
);
488488
if (!confirmed) return;
489489

490-
updateSettings({ colorMode: "system", activeThemeId: "t3code", accentHue: null });
491490
resetSettings();
492491
onRestored?.();
493-
}, [changedSettingLabels, onRestored, resetSettings, updateSettings]);
492+
}, [changedSettingLabels, onRestored, resetSettings]);
494493

495494
return {
496495
changedSettingLabels,

apps/web/src/hooks/useAppearance.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
1313
import type { ColorMode } from "@t3tools/contracts/settings";
1414
import type { DesktopAppearance } from "@t3tools/contracts";
15-
import { applyThemeTokens, findThemeById, removeThemeTokens, BUILT_IN_THEMES } from "~/lib/themes";
15+
import { applyThemeTokens, findThemeById, BUILT_IN_THEMES } from "~/lib/themes";
1616
import { useSettings, useUpdateSettings } from "./useSettings";
1717

1818
// ── Constants ────────────────────────────────────────────────────
@@ -138,8 +138,6 @@ export function useAppearance() {
138138

139139
// Sync to Electron
140140
syncDesktopAppearance({ mode: colorMode, themeId: activeThemeId, accentHue });
141-
142-
return () => removeThemeTokens();
143141
}, [resolvedTheme, activeTheme, accentHue, colorMode, activeThemeId]);
144142

145143
const setColorMode = useCallback(

apps/web/src/hooks/useSettings.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ export function buildLegacyClientSettingsMigrationPatch(
235235
export function migrateLocalSettingsToServer(): void {
236236
if (typeof window === "undefined") return;
237237

238-
const raw = localStorage.getItem(OLD_SETTINGS_KEY);
239-
if (!raw) return;
240-
241-
// Migrate old t3code:theme localStorage key to server colorMode
238+
// Migrate old t3code:theme localStorage key to server colorMode.
239+
// This runs independently of OLD_SETTINGS_KEY since the old useTheme hook
240+
// wrote t3code:theme separately.
242241
try {
243242
const oldTheme = localStorage.getItem("t3code:theme");
244243
if (oldTheme === "light" || oldTheme === "dark" || oldTheme === "system") {
@@ -250,6 +249,9 @@ export function migrateLocalSettingsToServer(): void {
250249
// Best-effort — don't block startup
251250
}
252251

252+
const raw = localStorage.getItem(OLD_SETTINGS_KEY);
253+
if (!raw) return;
254+
253255
try {
254256
const old = JSON.parse(raw);
255257
if (!Predicate.isObject(old)) return;

0 commit comments

Comments
 (0)