Repository navigation
Tolgee namespaces in NextJs #3348
Replies: 1 comment
|
Hello! Sorry for the delay and thanks for bringing this up 😊 The Tolgee React SDK is designed to work on both the client and server sides, including server‑side rendering and SEO, so it should integrate fully with your Next.js setup. We’ve looked into the problem but it’s unclear how to reproduce it. It sounds like you might be missing a namespace on the server, but we’re not sure what you mean by “Tolgee can’t detect the namespace from the key.” Could you please clarify that? To get to the bottom of this we really need a small example project and clear steps to reproduce. If you can share a minimal repository and the steps you follow to see the issue, we’ll be able to investigate and help fix it. The namespace docs at https://docs.tolgee.io/js-sdk/namespaces and the Next.js integration guide at https://docs.tolgee.io/js-sdk/integrations/react/next/app-router might also be useful. Thanks again for your patience and cooperation! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Issue A: Server-side namespace activation doesn't work for client components
The Problem:
Separate Tolgee instances: Next.js App Router uses separate Tolgee instances for server and client:
Timing issue:
// page.tsx (runs FIRST)
const tolgee = await getTolgee();
await tolgee.addActiveNs(seoContent?.seoContentVariables?.ns || '');
await tolgee.loadRequired();
Why it's unpredictable:
Server components work: They use the server instance where the namespace is activated
Client components fail: They use the client instance where the namespace isn't activated
Root Cause: Server-side namespace activation doesn't transfer to the client-side Tolgee instance. The staticData sent to the client is frozen at the layout level, before page-level namespace activation.
### Issue B: Key bloat in the DOM
The Problem:
In an effort to fix issue A, if I load namespaces on client side, Tolgee returns the raw key string instead of the translation on first paint. These raw keys end up showing to the user:
Why this happens:
Missing namespace: Client components try to translate before the namespace is loaded
Fallback behavior: When a translation isn't found, Tolgee returns the key itself
Impact:
Please advise on the matter.
All reactions