mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix(theme): use current theme as fallback in preferences, prevent session override of localStorage
This commit is contained in:
@@ -24,9 +24,9 @@ const AVATAR_COLORS = [
|
||||
|
||||
export const StepPreferences = () => {
|
||||
const { next, updateContext, state } = useOnboarding();
|
||||
const { setTheme } = useTheme();
|
||||
const { theme: currentTheme, setTheme } = useTheme();
|
||||
const preferences = state?.context.flowData.preferences ?? {
|
||||
theme: "dark" as const,
|
||||
theme: (currentTheme ?? "system") as ThemeKey,
|
||||
};
|
||||
const account = state?.context.flowData.account as
|
||||
| OnboardingAccountData
|
||||
|
||||
@@ -15,7 +15,13 @@ export function ThemeMetaUpdater() {
|
||||
|
||||
useEffect(() => {
|
||||
if (isPending || !session?.user?.theme) return;
|
||||
setTheme(session.user.theme);
|
||||
// Only apply the DB theme if the browser has no locally stored preference.
|
||||
// This prevents a stale session value from overriding a theme the user
|
||||
// just selected (localStorage is always written first by next-themes).
|
||||
const stored = localStorage.getItem("theme");
|
||||
if (!stored) {
|
||||
setTheme(session.user.theme);
|
||||
}
|
||||
}, [session, isPending, setTheme]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user