Skip to content

react-i18next SSR Not Working — Fix Server Rendering

DodaTech Updated 2026-06-24 1 min read

In this fix, you'll learn how to properly configure react-i18next for SSR. This matters for server-rendered multilingual pages, and appears in Next.js and custom SSR setups.

The Problem

The following code demonstrates the typical mistake:

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
i18n.use(initReactI18next).init({
  resources,
  lng: 'en',
});
// SSR output shows translation keys, not values

The Fix

Here is the corrected version:

export const createInstance = (lng) => {
  const instance = createInstance();
  instance.use(initReactI18next).init({
    resources, lng, fallbackLng: 'en',
    interpolation: { escapeValue: false },
  });
  return instance;
};
// SSR output shows translated values

Prevention

  • Create a fresh i18n instance per request to avoid cross-request state leakage.
  • Detect language from request (cookie, Accept-Language, or URL path).
  • Use react: { useSuspense: false } in SSR to avoid Suspense issues.
  • Load only needed namespaces for the current page.
  • For Next.js 13+, use app directory patterns with server-only/client-only imports.

Common Mistakes with i18n ssr

  1. Using return to exit a function early instead of wrapping a pure value in the monad
  2. Mixing let bindings with <- bindings in do notation, producing type errors
  3. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors

These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How is SSR different from client-side i18n?

Client i18n initializes once. Server creates a new instance per request with correct language, renders the page, and serializes translations for client hydration.

How do I pass translations from server to client?

Serialize resources and pass as script tag/page props. Client reads preloaded resources and skips fetching. Next.js next-i18next handles this automatically.

What are common SSR i18n pitfalls?

Shared instance across requests (language leaks), missing initReactI18next plugin, Suspense during server render, not preloading required namespace resources.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro