fix(react): allow explicit locale for static server rendering - #3528
fix(react): allow explicit locale for static server rendering#3528floze-the-genius wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesServer locale rendering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant StaticRoute
participant LocaleLayout
participant createServerInstance
participant Tolgee
StaticRoute->>LocaleLayout: provide locale route param
LocaleLayout->>createServerInstance: call getTolgee(locale)
createServerInstance->>Tolgee: create or retrieve locale instance
Tolgee-->>LocaleLayout: return configured instance
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/react/src/createServerInstance.tsx (1)
38-41: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winSupport explicit locale in the Server
<T>component.Since
getTranslatenow supports an explicitlocaleto bypassgetLocale()(and avoid request-boundheaders()usage that breaks static generation), the Server<T>component will still fail during static generation because it callsgetTranslate()without arguments.Consider adding an optional
localeprop to the server<T>component (e.g., by extendingTPropsor extracting it from the props) so users can safely use<T>in statically generated Server Components.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/react/src/createServerInstance.tsx` around lines 38 - 41, Add an optional locale prop to the server T component’s props and pass it to getTranslate, preserving the existing locale-resolution behavior when the prop is omitted so static generation can bypass request-bound locale detection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/react/src/createServerInstance.tsx`:
- Around line 38-41: Add an optional locale prop to the server T component’s
props and pass it to getTranslate, preserving the existing locale-resolution
behavior when the prop is omitted so static generation can bypass request-bound
locale detection.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: afd64097-7f98-4935-9361-73c3ebb1deb4
📒 Files selected for processing (5)
packages/react/src/createServerInstance.spec.tsxpackages/react/src/createServerInstance.tsxtestapps/next-app-intl/README.mdtestapps/next-app-intl/src/app/[locale]/layout.tsxtestapps/next-app-intl/src/app/[locale]/ssg/page.tsx
Summary
createServerInstancecallers to pass an explicit locale togetTolgeeandgetTranslategenerateStaticParamsregression route and example guidanceReproduction
Before the change, the regression route failed during
next buildwith:After passing the route locale to
getTolgee(locale), Next emits/en/ssg,/cs/ssg,/de/ssg, and/fr/ssgas SSG pages.Tests
pnpm --filter @tolgee/react test -- --runInBandpnpm --filter @tolgee/react buildpnpm --dir testapps/next-app-intl buildCloses #3526
Summary by CodeRabbit
localevia the serverTcomponent).Tlocale handling.