Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export default function RootLayout({
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{/* Wrap everything in ThemeProvider */}
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem>
{/* Wrap everything in ThemeProvider */}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved. thank you

<ThemeProvider attribute="class" defaultTheme="dark" enableSystem storageKey="devui-theme">
<SearchProvider>
<ThemeColorPicker />
<Header />
<ThemeColorPicker />
{children}
<Toaster position="top-center" richColors />
<BackToTopButton />
Expand Down
18 changes: 17 additions & 1 deletion src/components/ui/ThemeColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,29 @@ const ThemeColorPicker = () => {
// Load saved theme from localStorage on mount
useEffect(() => {
setMounted(true);

// Clean up any invalid theme names from next-themes localStorage
const nextThemesKey = 'devui-theme';
const nextThemesValue = localStorage.getItem(nextThemesKey);
if (nextThemesValue && nextThemesValue.includes(' ')) {
localStorage.removeItem(nextThemesKey);
}

const savedThemeName = localStorage.getItem(STORAGE_KEY);
const savedTheme = themes.find((t) => t.name === savedThemeName);

// Validate theme name - remove any invalid characters
const cleanThemeName = savedThemeName?.replace(/[^a-zA-Z0-9-_]/g, '');
const savedTheme = themes.find((t) => t.name === cleanThemeName);

if (savedTheme) {
// If a theme was saved, apply it
handleThemeChange(savedTheme, false); // Pass false to prevent re-saving
} else {
// Clean up invalid theme names from localStorage
if (savedThemeName && savedThemeName !== cleanThemeName) {
localStorage.removeItem(STORAGE_KEY);
}

// Otherwise, get the default color from CSS
const currentColor = getComputedStyle(document.body)
.getPropertyValue("--primary")
Expand Down