Skip to content

Commit 196c37b

Browse files
rishabh3562claude
andcommitted
fix: wrap ThemeProvider in client component for Next.js App Router compatibility
- Extract ThemeProvider into a separate client component (components/providers.tsx) - Fix theme toggle functionality by ensuring ThemeProvider runs on client-side - Resolves hydration mismatch and theme state persistence issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c7cc4b2 commit 196c37b

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

app/layout.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Metadata } from "next";
33
import { Inter } from "next/font/google";
44
import { SiteHeader } from "@/components/site-header";
55
import { SiteFooter } from "@/components/site-footer";
6-
import { ThemeProvider } from "next-themes";
6+
import { Providers } from "@/components/providers";
77

88
const inter = Inter({ subsets: ["latin"] });
99

@@ -21,19 +21,13 @@ export default function RootLayout({
2121
return (
2222
<html lang="en" suppressHydrationWarning>
2323
<body className={inter.className}>
24-
<ThemeProvider
25-
attribute="class"
26-
defaultTheme="system"
27-
enableSystem
28-
storageKey="devtools-theme"
29-
disableTransitionOnChange
30-
>
24+
<Providers>
3125
<div className="relative min-h-screen flex flex-col">
3226
<SiteHeader />
3327
<main className="flex-1">{children}</main>
3428
<SiteFooter />
3529
</div>
36-
</ThemeProvider>
30+
</Providers>
3731
</body>
3832
</html>
3933
);

components/providers.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use client";
2+
3+
import { ThemeProvider } from "next-themes";
4+
5+
export function Providers({ children }: { children: React.ReactNode }) {
6+
return (
7+
<ThemeProvider
8+
attribute="class"
9+
defaultTheme="system"
10+
enableSystem
11+
storageKey="devtools-theme"
12+
disableTransitionOnChange
13+
>
14+
{children}
15+
</ThemeProvider>
16+
);
17+
}

0 commit comments

Comments
 (0)