File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
reflex/.templates/web/utils Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments