lingui / lingui/js-lingui

Adopt next/root-params in Next.js RSC example and tutorial

Open
#2,645 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

⚫ Next.js 📖 documentation examples
Dominant language
TypeScript
Stars
5.9k
Forks
457
Avg merge
1d 23h
Merged PRs (30d)
16

Description

Next.js 16.3 introduced next/root-params, which lets any Server Component read root dynamic segments (e.g. [lang]) without prop drilling. This simplifies Lingui's RSC setup - no core changes needed, the improvements are in the example and docs.

Current state
  • Every page/layout in examples/nextjs-swc takes params, awaits it, and passes lang to initLingui(lang).
  • The RSC tutorial documents this caveat: "you need to repeat the setI18n in every page and layout… Please let us know if there's a known better way."
Proposed changes

Example (examples/nextjs-swc):

  • Upgrade Next.js 15.0.1 → 16.3+
  • Make initLingui() read the locale via next/root-params internally, so pages/layouts/generateMetadata call it with zero args and stop threading params

Docs (tutorials/react-rsc):

  • Update snippets to the root-params pattern; keep the params-prop approach for Next.js < 16.3
  • Rewrite the "Pages, Layouts and Lingui" section (the per-page call remains due to React cache ordering, but becomes a zero-arg one-liner)
  • Document caveats: not available in Client Components, Server Actions, or Route Handlers - pass the locale explicitly there
  • Optionally: note that root-param getters are tracked in 'use cache' cache keys, so getI18nInstance(await lang()) inside cached functions is keyed per locale
Notes

Lingui's server-side useLingui()/Trans are sync and can't lazily resolve the locale themselves, so initLingui() per page/layout is still required. Removing it entirely would need an async init path in @lingui/react/server - out of scope here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in examples/nextjs-swc by inspecting the current Next.js version, initLingui usage, and params flow, then review tutorials/react-rsc for the existing RSC guidance. Done means the example uses next/root-params with the documented version boundary, and the tutorial covers zero-argument initialization plus the listed Client Component, Server Action, and Route Handler caveats.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, typescript
Domain
documentation, internationalization, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.