fix(theme): ThemeSessionBridge no longer reverts user theme selections

Effect deps included `theme`, causing the bridge to re-fire on every
client-side theme change and call setTheme(session.user.theme). Because
the PUT to /api/me/theme does not refresh the better-auth session,
session.user.theme stays at the pre-change value and clobbers the new
selection — toast says "Theme updated" but UI stays on the prior theme.

Sync only on session identity change (sign-in / sign-out). Matches the
planning intent ("on session load and after sign-in").

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
lorentz 2026-05-14 09:04:10 -04:00
parent 7b644e475f
commit 10c68657a7

View file

@ -32,7 +32,14 @@ export function ThemeSessionBridge() {
setTheme(serverTheme);
}
}
}, [session?.user, theme, setTheme]);
// Deps intentionally exclude `theme`. This bridge syncs server → client
// on session establishment only. Including `theme` made the effect re-fire
// on every user selection and revert to the stale cached
// `session.user.theme` (the PUT to /api/me/theme does not refresh the
// better-auth session, so user.theme remains the pre-change value and
// "wins" against the new client value).
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session?.user?.id, setTheme]);
return null;
}