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.
This commit is contained in:
Cursor Agent committed 2026-03-29 19:02:02 +00:00
1 parent f4ab7ebe21
commit 57ebd82da6
3 files changed
+9 -10

No files matched your search

@@ -424,7 +424,7 @@ function AboutVersionSection() {
export function useSettingsRestore(onRestored?: () => void) {
const settings = useSettings();
const { updateSettings, resetSettings } = useUpdateSettings();
const { resetSettings } = useUpdateSettings();
const isGitWritingModelDirty = !Equal.equals(
settings.textGenerationModelSelection ?? null,
@@ -487,10 +487,9 @@ export function useSettingsRestore(onRestored?: () => void) {
);
if (!confirmed) return;
updateSettings({ colorMode: "system", activeThemeId: "t3code", accentHue: null });
resetSettings();
onRestored?.();
}, [changedSettingLabels, onRestored, resetSettings, updateSettings]);
}, [changedSettingLabels, onRestored, resetSettings]);
return {
changedSettingLabels,
+1 -3
View File
@@ -12,7 +12,7 @@
import { useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
import type { ColorMode } from "@t3tools/contracts/settings";
import type { DesktopAppearance } from "@t3tools/contracts";
import { applyThemeTokens, findThemeById, removeThemeTokens, BUILT_IN_THEMES } from "~/lib/themes";
import { applyThemeTokens, findThemeById, BUILT_IN_THEMES } from "~/lib/themes";
import { useSettings, useUpdateSettings } from "./useSettings";
// ── Constants ────────────────────────────────────────────────────
@@ -138,8 +138,6 @@ export function useAppearance() {
// Sync to Electron
syncDesktopAppearance({ mode: colorMode, themeId: activeThemeId, accentHue });
return () => removeThemeTokens();
}, [resolvedTheme, activeTheme, accentHue, colorMode, activeThemeId]);
const setColorMode = useCallback(
+6 -4
View File
@@ -235,10 +235,9 @@ export function buildLegacyClientSettingsMigrationPatch(
export function migrateLocalSettingsToServer(): void {
if (typeof window === "undefined") return;
const raw = localStorage.getItem(OLD_SETTINGS_KEY);
if (!raw) return;
// Migrate old t3code:theme localStorage key to server colorMode
// Migrate old t3code:theme localStorage key to server colorMode.
// This runs independently of OLD_SETTINGS_KEY since the old useTheme hook
// wrote t3code:theme separately.
try {
const oldTheme = localStorage.getItem("t3code:theme");
if (oldTheme === "light" || oldTheme === "dark" || oldTheme === "system") {
@@ -250,6 +249,9 @@ export function migrateLocalSettingsToServer(): void {
// Best-effort — don't block startup
}
const raw = localStorage.getItem(OLD_SETTINGS_KEY);
if (!raw) return;
try {
const old = JSON.parse(raw);
if (!Predicate.isObject(old)) return;