#How to fix this Hydration Error (post Localization Implementation)
1 messages ยท Page 1 of 1 (latest)
I had to update my page.tsx / layout.tsx and my middleware file in order to implement translation for my website.
Now I get this error but the page loads and the translation works.
Does anyone know what could cause this issue ?
Code for the logo component:
// RiveLogo.tsx
'use client';
import { useRive } from '@rive-app/react-canvas';
import { useTheme } from 'next-themes';
function RiveLogoComponent(props: { src: string }) {
const { RiveComponent } = useRive({
src: props.src,
autoplay: true,
});
return <RiveComponent />;
}
const RiveLogo = () => {
const { resolvedTheme } = useTheme();
console.log("Current theme:", resolvedTheme); // Log the current theme
const logoSrc = resolvedTheme === 'dark'
? "/JobsBringerLogoDarkAnimated.riv"
: "/JobsBringerLogoLightAnimated.riv";
return (
<div style={{ width: '300px', height: '300px', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<RiveLogoComponent key={resolvedTheme} src={logoSrc} />
</div>
);
};
export default RiveLogo;
And on my log-in page I import it like this:
import RiveLogo from '../../../components/RiveLogo';
<div className="flex flex-col items-center justify-center w-full px-8 sm:max-w-md">
<RiveLogo />
are you sure the paths are correct
for the logos
Hmm I can share the relative paths here:
app/[lang]/login/page.tsx
components/RiveLogo.tsx
Oh yeah, definitely. I didn't change those and they worked before.
The logo worked just fine before implementing this localization functionality
I didn't get hydration errors either
public/JobsBringerLogoDarkAnimated.riv
I mean here is the path
if it would be a app/login, then /JobsBringerLogoDarkAnimated.riv would be fine, but since its app/[lang]/login
I didn't change it or anything, why it wouldn't work all of a sudden
then it should be
'../JobsBringerLogoDarkAnimated.riv'
or './JobsBringerLogoDarkAnimated.riv'
not quite sure
'/../JobsBringerLogoDarkAnimated.riv' maybe
import RiveLogo from '../../../components/RiveLogo';
This is how I have it right now
i mean here
That is correct because that didn't change
i have no idea then honestly, ask an ai i guess and provide file structure
ohh
See, the components folder has nothing to do with my app folder
it should be /icons/JobsBringerLogoDarkAnimated.riv
oh yes
It's directly inside the public folder ๐
maybe try console logging the src prop
to see if its correct
I think the issue may be here
Since I didn't update the path but for some reason it doesn't show any errors
And if I try to update it with someting else it gives error
delete this line and import it like this maybe
so vs code may choose path instead of you
It did!
now does it work?
No, I even restarted the server
i dont know what to do then, maybe try checking your old code to find the solution
before you added [lang]
Hmm, for the login page at least even if I use the old code it won't load the logo
The issue must be coming from another page then
either layout or page.tsx
i guess thats it
I replaced those files too and reloaded the website, still the same even without that hydration error.