#How to fix this Hydration Error (post Localization Implementation)

1 messages ยท Page 1 of 1 (latest)

hybrid grove
#

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 />
burnt laurel
#

for the logos

hybrid grove
#

Hmm I can share the relative paths here:

app/[lang]/login/page.tsx
components/RiveLogo.tsx

burnt laurel
#

i mean image paths

#

and are you sure the file extension is .riv and not .rive

hybrid grove
#

The logo worked just fine before implementing this localization functionality

#

I didn't get hydration errors either

burnt laurel
#

i think its file paths issue

#

in this case

#

yep, it surely is

hybrid grove
#

public/JobsBringerLogoDarkAnimated.riv

I mean here is the path

burnt laurel
hybrid grove
#

I didn't change it or anything, why it wouldn't work all of a sudden

burnt laurel
#

then it should be

#

'../JobsBringerLogoDarkAnimated.riv'

#

or './JobsBringerLogoDarkAnimated.riv'

#

not quite sure

#

'/../JobsBringerLogoDarkAnimated.riv' maybe

hybrid grove
#

import RiveLogo from '../../../components/RiveLogo';

#

This is how I have it right now

burnt laurel
#

i mean here

hybrid grove
#

That is correct because that didn't change

burnt laurel
#

i have no idea then honestly, ask an ai i guess and provide file structure

hybrid grove
burnt laurel
#

ohh

hybrid grove
#

See, the components folder has nothing to do with my app folder

burnt laurel
#

it should be /icons/JobsBringerLogoDarkAnimated.riv

hybrid grove
#

It's not inside the icons folder either

#

If you look closely

burnt laurel
#

oh yes

hybrid grove
#

It's directly inside the public folder ๐Ÿ˜„

burnt laurel
#

to see if its correct

hybrid grove
#

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

burnt laurel
#

so vs code may choose path instead of you

hybrid grove
burnt laurel
#

now does it work?

hybrid grove
#

No, I even restarted the server

burnt laurel
#

i dont know what to do then, maybe try checking your old code to find the solution

#

before you added [lang]

hybrid grove
#

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

burnt laurel
#

i guess thats it

hybrid grove
#

I replaced those files too and reloaded the website, still the same even without that hydration error.

hybrid grove