-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle hydration errors? SEO? #50
Comments
any updates on this problem ? i have hydration errors even for same language since translation key is not same as translation value ex: |
I am also very interested in a solution to this problem ;) |
Hi everyone, Thank you for reaching out. I will look into it. Cheers |
Found a "solution" to this issue, just pass the property <p suppressHydrationWarning>
{t("some.key")}
</p> |
If SEO is an issue for your project just enter to https://next-export-i18n-example.vercel.app/ and view page source, in every language the body text is the same to search engines regardless of the language you are in, so it is not advisable. |
I'm guessing that What I did to get around this is ensure that the client is rendered first using import { useState, useEffect } from "react";
import { useTranslation, useLanguageQuery } from "next-export-i18n";
export default TestPage = () => {
const { t } = useTranslation();
const [query] = useLanguageQuery();
const [isClient, setIsClient] = useState<boolean>(false);
useEffect(() => {
setIsClient(true);
}, []);
return (
isClient && (
<div>
<main>{t("home.hero.title")}</main>
</div>
)
);
}; |
@martinkr But this is not the best solution. |
@martinkr Do we have any solution for this yet? |
Is this a real problem do we really know that Google cannot crawl properly the website if we set the language client side? An alternative could be to create static pages for each language, just for search engines. |
Hi,
when
useBrowserDefault
is set totrue
and the users browser language is different as set indefaultLang
there will be fired hydrations errors ("Text content does not match server-rendered HTML."). This is expected as the client site renders a different language than generated on the server.You can reproduce the issue on the example page (https://next-export-i18n-example.vercel.app/) if you change the browser language to something other than german (as here
defaultLang
is set tode
).This is my first static next.js project so I'm wondering how to handle this?
I'm also wondering how SEO works for languages that are not set as
defaultLang
as this languages are not created as static files.The text was updated successfully, but these errors were encountered: