-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Bug]: Hydration failed #317
Comments
Hey bro, You need to make sure that the next-theme provider is mounted before returning it, like this:
I also found this library that seems to solve the problem but to be honest I have not tried it: https://www.reddit.com/r/nextjs/comments/1dy0enr/new_theming_library_specifically_for_next_with_no/ |
Isn't this intended behavior? I haven't gotten this error before the Next 15 release, but the readme says to add the |
@kareem717 Your solution is valid but it does not work to make ssr |
I mean... obviously - the whole provider is a client component either way, it's built that way. In the README it says "Note that ThemeProvider is a client component, not a server component." Try the library I tagged - I think it might solve the issue if you want it to be SSR |
If you want to do it like that, that seems to be a way to do so. I haven't had this problem until next 15 as well |
First of all, NextJS pre-renders client components on the server (source). So by returning The library you linked would solve the problem for SSR (and would actually work better for SSR), but because it uses cookies to handle theme data, it opts out of SSG, which for many is a dealbreaker. There is a prop to disable it for a route (which would enable SSG), but this isn't a very elegant solution. This hydration error is fairly insignificant. React is able to sort everything out on its own, and we expect the |
Aye fair enough. Thanks for the tip. |
@kareem717 & @maxwiseman, thoughts on the proposed solution in this comment? i.e. wrapping the |
@gfargo That doesn't solve it for me. Does the error come back after you reload the page? Hydration errors can go away when you edit a file with the dev server running, but they sometimes come back after reloading the page. I could be wrong, but I don't think next-themes/next-themes/src/index.tsx Lines 135 to 138 in bf0c5a4
|
Please read the docs: https://github.com/pacocoursey/next-themes?tab=readme-ov-file#with-app |
I have a question, if next-themes is a client component, so will this actually block the RSCs? I am not sure that if we use a client component to wrap some server and client components, they will all go client component, which is SSR as well. |
|
Use this to prevent hydration errors: https://github.com/victorteokw/next-safe-themes |
What happened?
in recent version next js 15 not working
Version
0.3.0
What browsers are you seeing the problem on?
No response
The text was updated successfully, but these errors were encountered: