Getting Text content does not match server-rendered HTML, NEXT - 13
Unanswered
Japanese Bobtail posted this in #help-forum
Japanese BobtailOP
Hello !
I am using
I am fetching data based on the current slug. the slug is dynamic i have named the files as
here is the code for fetching translation.
more code
I am using
next 13. I am getting the the above error.I am fetching data based on the current slug. the slug is dynamic i have named the files as
[...slug].tsx and I need to fetch data from the server. its for the translation. and from the client as well.here is the code for fetching translation.
export const getServerSideProps = async ({ locale } : {locale: string}) => {
return {
props: {
...(await serverSideTranslations(locale ?? 'en', [
'header',
'footer'
]
)),
},
}
}
what am i missing ?more code
const Page = () => {
const router = useRouter();
const slug = router.asPath;
const { data, isLoading, error } = useQuery({
queryKey: [slug],
queryFn: () => {
return PageService.fetchPublicPageData('fetching data based on current slug');
},
enabled: slug !== undefined && slug !== '/[...slug]',
});
if (data) {
const { title_in_english, title_in_nepali, page_type } = data;
const title = router.locale === 'np' ? title_in_nepali : title_in_english;
const handlePageWiseContent = () => {
switch (page_type) {
case 'REPORT':
return <ReportTypePageComponent data={data} />;
case 'PDF-VIEWER':
return <PDFTypePageComponent data={data} />;
default:
return <WYSWYGTypePageComponent data={data} />;
}
};
return (
<div className="container flex flex-col gap-3">
<h1 className={'text-2xl sm:text-3xl font-bold noto-fonts mb-5'}>{title}</h1>
{handlePageWiseContent()}
</div>
);
}
};
export const getServerSideProps = async ({ locale } : {locale: string}) => {
return {
props: {
...(await serverSideTranslations(locale ?? 'en', [
'header',
'footer'
]
)),
},
}
}
export default Page;3 Replies
You might have to try disabling SSR for some of those components using something like [dynamic imports](https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#skipping-ssr)
Try commenting out some code and checking which of those components is throwing the error then skip SSR for that
(i have not taken a careful look at the code, i am just suggesting a fix that could potentially fix the problem)