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 = () => {
|
export const StepPreferences = () => {
|
||||||
const { next, updateContext, state } = useOnboarding();
|
const { next, updateContext, state } = useOnboarding();
|
||||||
const { setTheme } = useTheme();
|
const { theme: currentTheme, setTheme } = useTheme();
|
||||||
const preferences = state?.context.flowData.preferences ?? {
|
const preferences = state?.context.flowData.preferences ?? {
|
||||||
theme: "dark" as const,
|
theme: (currentTheme ?? "system") as ThemeKey,
|
||||||
};
|
};
|
||||||
const account = state?.context.flowData.account as
|
const account = state?.context.flowData.account as
|
||||||
| OnboardingAccountData
|
| OnboardingAccountData
|
||||||
|
|||||||
@@ -15,7 +15,13 @@ export function ThemeMetaUpdater() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isPending || !session?.user?.theme) return;
|
if (isPending || !session?.user?.theme) return;
|
||||||
|
// 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);
|
setTheme(session.user.theme);
|
||||||
|
}
|
||||||
}, [session, isPending, setTheme]);
|
}, [session, isPending, setTheme]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user