Skip to content

Commit 5952c68

Browse files
committed
pass the tests
1 parent 43a5159 commit 5952c68

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

reflex/.templates/web/utils/react-theme.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function ThemeProvider({ children, defaultTheme = "system" }) {
3737
if (lastCompiledTheme !== defaultColorMode) {
3838
// on app startup, make sure the application color mode is persisted correctly.
3939
localStorage.setItem("last_compiled_theme", defaultColorMode);
40+
setIsInitialized(true);
4041
return;
4142
}
4243
}
@@ -70,9 +71,11 @@ export function ThemeProvider({ children, defaultTheme = "system" }) {
7071
};
7172
});
7273

73-
// Save theme to localStorage whenever it changes (but not on initial mount)
74+
// Save theme to localStorage whenever it changes
75+
// Skip saving only if theme key already exists and we haven't initialized yet
7476
useEffect(() => {
75-
if (!isInitialized) return;
77+
const existingTheme = localStorage.getItem("theme");
78+
if (!isInitialized && existingTheme !== null) return;
7679
localStorage.setItem("theme", theme);
7780
}, [theme]);
7881

@@ -82,7 +85,7 @@ export function ThemeProvider({ children, defaultTheme = "system" }) {
8285
root.classList.remove("light", "dark");
8386
root.classList.add(resolvedTheme);
8487
root.style.colorScheme = resolvedTheme;
85-
}, [resolvedTheme]);
88+
}, [resolvedTheme, isInitialized]);
8689

8790
return createElement(
8891
ThemeContext.Provider,

0 commit comments

Comments
 (0)