pmndrs / react-three-next

React Three Fiber, Threejs, Nextjs starter
https://react-three-next.vercel.app/
MIT License
2.52k stars 342 forks source link

Hydration error #121

Closed marchitecht closed 1 year ago

marchitecht commented 1 year ago

Hello!

Is there anyone knows how to fix this hydration error?

I tried already both static and dynamic imports.

What am I doing wrong? image

netgfx commented 1 year ago

You are probably trying to change something at runtime, which results in being different from what the server of nextjs pre-compiled. Usually to avoid this (apart from relying on SSR (server side rendering) only for displaying the content) Is to make any modifications inside a useEffect (SSR doesn't validate code inside useEffect) Or you can try to conditionally render values whether or not the DOM window exists (on SSR there is no window or document).

If the above don't make much sense, try to do some look up on how SSR works and specifically NextJS (their documentation is pretty ok)