From 10c68657a766cb4274d4f27983b1b3f3bb85d310 Mon Sep 17 00:00:00 2001 From: lorentz Date: Thu, 14 May 2026 09:04:10 -0400 Subject: [PATCH] fix(theme): ThemeSessionBridge no longer reverts user theme selections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- components/mobile/profile/ThemeSessionBridge.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/mobile/profile/ThemeSessionBridge.tsx b/components/mobile/profile/ThemeSessionBridge.tsx index 0acc135..5e5b3c4 100644 --- a/components/mobile/profile/ThemeSessionBridge.tsx +++ b/components/mobile/profile/ThemeSessionBridge.tsx @@ -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; }