Error: Hydration failed because the initial UI does notmatch what was rendered
Answered
Gray-crowned Yellowthroat posted this in #help-forum
Gray-crowned YellowthroatOP
Error: Hydration failed because the initial UI does not
Match what was rendered . How to solve this
Match what was rendered . How to solve this
Answered by joulev
@Gray-crowned Yellowthroat the reason is: Radix modals cannot be forced open during prerendering
20 Replies
ThemeProvider must be a client component. Use "use client" at the top of the ThemeProvider component.
@Gray-crowned Yellowthroat Error: Hydration failed because the initial UI does not
Match what was rendered . How to solve this
Likely you set up next-themes wrong, give a repro repository
Tawny-shouldered Blackbird
@Clown ThemeProvider must be a client component. Use "use client" at the top of the ThemeProvider component.
Tawny-shouldered Blackbird
Check out the themeprovider here , I already used "use client" still its not working\
welp i cant even run that for some reason
cause the next server just crashes without error
@joulev Likely you set up next-themes wrong, give a repro repository
Gray-crowned YellowthroatOP
Whats wrong with the code
@Gray-crowned Yellowthroat Whats wrong with the code
ok the next-themes code is perfectly fine
i don't have the db connection and whatnot so can't test, can you screenshot for me the whole hydration error in the browser console (not the nextjs error overlay)?
including the stack trace since it is very important to debug hydration errors
@Gray-crowned Yellowthroat Whats wrong with the code
American
after downloading your file and trying to run it. It looks like the problem is in your InitialModal component because when I remove the InitialModal component no errors appear. but I still don't know what the problem is. and the next-themes provider working fine.
oh thanks a lot kizuna, that helped
@Gray-crowned Yellowthroat the reason is: Radix modals cannot be forced open during prerendering
Answer
this is a known radix bug
so instead of
<Dialog open>, i think you have to make a modalIsOpen state that is initialised to false, then in a useEffect set it to true@joulev <@925425428628398191> the reason is: Radix modals cannot be forced open during prerendering
American
ah... turns out that was the problem. thank you I learned something new from this 

reason why i know this: i faced this exact error before, more times than i'd like to admit
Tawny-shouldered Blackbird
Thank you so much man it really helped a lot
@joulev oh thanks a lot kizuna, that helped
Tawny-shouldered Blackbird
Thank you so much man really been stressing it from yesterday 🙂