Open rajks24 opened 1 year ago
this issue occurs for npm run dev
, and not for npm run build
. The issue was resolved after adding suppressHydrationWarning
in layout Eg: <html lang="en" suppressHydrationWarning>
. Seems occurs as needed because using next-themes .
Hello, how can I solve this problem?
Same warning here.
This issue still exists
+1 to the issue
Still exists.
The issue is fixed after adding suppressHydrationWarning
in layout Eg: <html lang="en" suppressHydrationWarning>
It is also part of the documentation in shadcn, I in the dark mode section
The issue is fixed after adding
suppressHydrationWarning
in layout Eg:<html lang="en" suppressHydrationWarning>
It is also part of the documentation in shadcn, I in the dark mode section
I think it should be at least mentioned in the docs. The suppressHydrationWarning
is not even highlighted, it's hard to spot the first time.
Still exists. In the Dark Mode
+1 issue
Hiding
The issue is fixed after adding
suppressHydrationWarning
in layout Eg:<html lang="en" suppressHydrationWarning>
It is also part of the documentation in shadcn, I in the dark mode section
I guess hiding warnings is considered a solution these days.
If the error is caused by shadcn themeprovider and goes way by removing this element then rather than suppressing the warning, you could also lazy load the ThemeProvider as highlighted here https://github.com/pacocoursey/next-themes?tab=readme-ov-file#avoid-hydration-mismatch
Note: Please test the production build, this might throw dynamic server usage error during build and using "force-dynamic" might help to resolve this
// layout.tsx
import dynamicImport from "next/dynamic";
export const dynamic = "force-dynamic"; // this might resolve the dynamic server usage error
const ThemeProvider = dynamicImport(
() => import("@/components/theme-provider").then((mod) => mod.ThemeProvider),
{
ssr: false,
loading: () => (
// Optional: Add skeleton loader here
<div className="min-h-screen bg-background" />
),
}
);
export default function RootLayout({ children }: Readonly<Props>) {
return (
<html lang="en">
<body
className={cn(
"min-h-screen bg-background font-sans antialiased",
inter.variable
)}
>
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
{children}
</ThemeProvider>
</body>
</html>
);
}```
Issue : getting warning in console for Extra attributes from the server: class,style
template version: "version": "0.1.0"
Description:
Getting warning when run
npm run dev
in browser console