Skip to content

Commit a983158

Browse files
fix:DOMTokenList error (#224)
* bug:DOMTokenList error * Resolve merge conflict: combine Header component with theme features * removed addition header * fix:parsing error
1 parent 8583294 commit a983158

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/app/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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 />

src/components/ui/ThemeColorPicker.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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-zA-Z0-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")

0 commit comments

Comments
 (0)