Performance: Server component translations
This affects the initial page load speed by offloading translation rendering to the server, reducing client-side JavaScript and improving Largest Contentful Paint (LCP).
import { getTranslations } from '@/lib/i18n'; export default async function Greeting({ params }) { const t = await getTranslations(params.locale); return <p>{t('hello')}</p>; }
import { useTranslation } from 'next-i18next/client'; export default function Greeting() { const { t } = useTranslation(); return <p>{t('hello')}</p>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side translation in React component | Moderate (due to hydration) | 1 reflow after hydration | Higher paint cost due to delayed content | [X] Bad |
| Server component translation rendering | Minimal (static HTML) | 0 reflows on load | Lower paint cost, faster LCP | [OK] Good |
import { getTranslations } from 'next-intl/server';
export default async function Greeting() {
const t = await getTranslations();
return <h1>{t('greeting')}</h1>;
}import { getTranslations } from 'next-intl/server';
export default async function Welcome() {
const t = await getTranslations('common');
return <div>{t('welcome')}</div>;
}
Assuming translations for 'common' namespace are not loaded.defaultMessage option in t() to provide a custom English fallback string.Pass the test and this pattern moves unknown