-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning: Extra attributes from the server: data-theme,style with App router #231
Comments
Hey! I've come to the same problem as you and found useful discussions about it on issue #180 and this discussion. |
I faced the same kind of problem today. On my side I choose to use the: "isClient" technic which will: "Ensure that the component renders the same content server-side as it does during the initial client-side render to prevent a hydration mismatch." And it solve my problem 👍 PS: on my side (still don't understand why) I need to do this when I declare the ThemeProvider, like this: "use client";
import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { type ThemeProviderProps } from "next-themes/dist/types";
import { useEffect, useState } from "react";
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
// Ensure that the component renders the same content server-side as it does during the initial client-side render to prevent a hydration mismatch.
const [isClient, setIsClient] = useState(false);
useEffect(() => {
setIsClient(true);
}, []);
return (
isClient && <NextThemesProvider {...props}>{children}</NextThemesProvider>
);
} |
This will result in the Server Component below the ThemeProvider not being rendered during the pre-rendering process. You can open the Network tab in your browser's DevTools to check the document received when the page initially loads. |
Yep you are right, I use now this system only in composants/page where I have the hydration issue. But tbh, I always have the impression the hydration error appear randomly (sometimes I have it, sometimes no on certain components) |
Hello,
I am unsure what am I doing wrong but themese work fine, but I'm getting the following warning in my console:
I am using Next 14, app router.
The Theme provider is added to my
layout.tsx
as followingThis is the layout
This is the provider
The text was updated successfully, but these errors were encountered: