Skip to content

The agent that grows with you

fix(desktop): keep the saved skin name until the registry can resolve it

Brooklyn Nicholson1d1411df9caa
diff --git a/apps/desktop/src/themes/context.test.tsx b/apps/desktop/src/themes/context.test.tsx
index 144eca0f6db..780f9155625 100644
--- a/apps/desktop/src/themes/context.test.tsx
+++ b/apps/desktop/src/themes/context.test.tsx
@@ -68,6 +68,29 @@ describe('ThemeProvider ← backend skin sync', () => {
)
expect(cssVar('--theme-foreground')).toBe('#ff9f0a')
})
+
+ // The relaunch bug: the persisted pick was a backend skin, and the boot paint
+ // ran before the gateway seeded it. `normalizeSkin` could not resolve the
+ // name, flattened it to the default, and the connect-time seed (apply: false,
+ // by design) never repainted — so the theme "didn't stick" until `/skin`.
+ it('paints a persisted backend skin once the connect-time seed makes it resolvable', () => {
+ window.localStorage.setItem('hermes-desktop-theme-v2', 'bloomberg')
+
+ render(
+ <ThemeProvider>
+ <div />
+ </ThemeProvider>
+ )
+
+ // Boot: nothing resolves 'bloomberg' yet → default paint...
+ expect(cssVar('--theme-background-seed')).not.toBe('#000000')
+
+ // ...but the pick survives, so the seed alone repaints it.
+ act(() => ingestBackendSkin(bloomberg('#ff9f0a'), { apply: false }))
+
+ expect(cssVar('--theme-background-seed')).toBe('#000000')
+ expect(skinPref.resolve('default')).toBe('bloomberg')
+ })
})
describe('ThemeProvider highlight preview', () => {
diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsx
index d2024906a4d..44635d50877 100644
--- a/apps/desktop/src/themes/context.tsx
+++ b/apps/desktop/src/themes/context.tsx
@@ -68,20 +68,31 @@ const normalizeMode = (value: string | null): ThemeMode =>
// it *is* the legacy global slot, so it reads/writes the global directly. Named
// profiles get their own entry and fall back to that global until assigned, so
// unassigned profiles and pre-per-profile installs stay on the global value.
-const profilePref = <T extends string>(record: string, legacy: string, normalize: (v: string | null) => T) => ({
- resolve: (profile: string): T => normalize(storedStringRecord(record)[profile] ?? storedString(legacy)),
- assign: (profile: string, value: T): void => {
- if (profile === 'default') {
- persistString(legacy, value)
- } else {
- persistStringRecord(record, { ...storedStringRecord(record), [profile]: value })
+const profilePref = <T extends string>(record: string, legacy: string, normalize: (v: string | null) => T) => {
+ const stored = (profile: string): string | null => storedStringRecord(record)[profile] ?? storedString(legacy)
+
+ return {
+ /** The pick as written, un-normalized. */
+ stored,
+ resolve: (profile: string): T => normalize(stored(profile)),
+ assign: (profile: string, value: T): void => {
+ if (profile === 'default') {
+ persistString(legacy, value)
+ } else {
+ persistStringRecord(record, { ...storedStringRecord(record), [profile]: value })
+ }
}
}
-})
+}
export const skinPref = profilePref(PROFILE_SKINS_KEY, SKIN_KEY, normalizeSkin)
export const modePref = profilePref(PROFILE_MODES_KEY, MODE_KEY, normalizeMode)
+// Provider state keeps the raw pick so a name nothing resolves YET (a backend
+// skin the gateway hasn't seeded on this launch) isn't flattened to the default
+// for the rest of the session — it paints as soon as the registry can resolve it.
+const storedSkin = (profile: string): string => skinPref.stored(profile) ?? DEFAULT_SKIN_NAME
+
/** Everything a peer window could change that this one has to repaint for. */
const APPEARANCE_KEYS = new Set([SKIN_KEY, PROFILE_SKINS_KEY, MODE_KEY, PROFILE_MODES_KEY])
@@ -387,7 +398,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
)
const [themeName, setThemeNameState] = useState(() =>
- typeof window === 'undefined' ? DEFAULT_SKIN_NAME : skinPref.resolve(readBootProfileKey())
+ typeof window === 'undefined' ? DEFAULT_SKIN_NAME : storedSkin(readBootProfileKey())
)
const [mode, setModeState] = useState<ThemeMode>(() =>
@@ -398,7 +409,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
// remember it for the next boot's first paint.
useEffect(() => {
rememberActiveProfileKey(profileKey)
- setThemeNameState(skinPref.resolve(profileKey))
+ setThemeNameState(storedSkin(profileKey))
setModeState(modePref.resolve(profileKey))
}, [profileKey])
@@ -414,7 +425,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
const live = normalizeProfileKey($activeGatewayProfile.get())
- setThemeNameState(skinPref.resolve(live))
+ setThemeNameState(storedSkin(live))
setModeState(modePref.resolve(live))
}
@@ -431,7 +442,16 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
// committed appearance.
const [preview, setPreview] = useState<{ name: string; mode: 'light' | 'dark' } | null>(null)
- const paintedName = preview ? preview.name : themeName
+ // The committed skin, resolved against the CURRENT registry — so a stored
+ // backend skin that failed to resolve at boot paints once the gateway seeds it.
+ const committedName = useMemo(
+ () => normalizeSkin(themeName),
+ // normalizeSkin resolves through the merged registry; the stores are its reactivity.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ [themeName, userThemes, backendThemes, registryVersion]
+ )
+
+ const paintedName = preview ? preview.name : committedName
const paintedMode = preview ? preview.mode : resolvedMode
const activeTheme = useMemo(
@@ -503,7 +523,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
const value = useMemo<ThemeContextValue>(
() => ({
theme: paintedTheme,
- themeName,
+ themeName: committedName,
mode,
resolvedMode,
renderedMode,
@@ -515,7 +535,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
}),
[
paintedTheme,
- themeName,
+ committedName,
mode,
resolvedMode,
renderedMode,