File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,11 +35,11 @@ export default function RootLayout({
3535 < body
3636 className = { `${ geistSans . variable } ${ geistMono . variable } antialiased` }
3737 >
38- { /* Wrap everything in ThemeProvider */ }
39- < ThemeProvider attribute = "class" defaultTheme = "dark" enableSystem >
38+ { /* ✅ Wrap everything in ThemeProvider */ }
39+ < ThemeProvider attribute = "class" defaultTheme = "dark" enableSystem storageKey = "devui-theme" >
4040 < SearchProvider >
41- < ThemeColorPicker />
4241 < Header />
42+ < ThemeColorPicker />
4343 { children }
4444 < Toaster position = "top-center" richColors />
4545 < BackToTopButton />
Original file line number Diff line number Diff line change @@ -27,13 +27,29 @@ const ThemeColorPicker = () => {
2727 // Load saved theme from localStorage on mount
2828 useEffect ( ( ) => {
2929 setMounted ( true ) ;
30+
31+ // Clean up any invalid theme names from next-themes localStorage
32+ const nextThemesKey = 'devui-theme' ;
33+ const nextThemesValue = localStorage . getItem ( nextThemesKey ) ;
34+ if ( nextThemesValue && nextThemesValue . includes ( ' ' ) ) {
35+ localStorage . removeItem ( nextThemesKey ) ;
36+ }
37+
3038 const savedThemeName = localStorage . getItem ( STORAGE_KEY ) ;
31- const savedTheme = themes . find ( ( t ) => t . name === savedThemeName ) ;
39+
40+ // Validate theme name - remove any invalid characters
41+ const cleanThemeName = savedThemeName ?. replace ( / [ ^ a - z A - Z 0 - 9 - _ ] / g, '' ) ;
42+ const savedTheme = themes . find ( ( t ) => t . name === cleanThemeName ) ;
3243
3344 if ( savedTheme ) {
3445 // If a theme was saved, apply it
3546 handleThemeChange ( savedTheme , false ) ; // Pass false to prevent re-saving
3647 } else {
48+ // Clean up invalid theme names from localStorage
49+ if ( savedThemeName && savedThemeName !== cleanThemeName ) {
50+ localStorage . removeItem ( STORAGE_KEY ) ;
51+ }
52+
3753 // Otherwise, get the default color from CSS
3854 const currentColor = getComputedStyle ( document . body )
3955 . getPropertyValue ( "--primary" )
You can’t perform that action at this time.
0 commit comments