fix: Use useTranslation() hook server-side for proper i18n SSR#639
Merged
baptistegrimaud merged 1 commit intomainfrom Feb 25, 2026
Merged
fix: Use useTranslation() hook server-side for proper i18n SSR#639baptistegrimaud merged 1 commit intomainfrom
baptistegrimaud merged 1 commit intomainfrom
Conversation
2a3fdcc to
0d083e3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses i18n conflicts when rendering multiple JavaScript modules on the same page by ensuring translations resolve against the correct module namespace during SSR and hydration (Issue #317).
Changes:
- Replace direct
tusage from thei18nextsingleton withuseTranslation()in server-rendered React components (samples and template). - Set
defaultNSonI18nextProviderduring SSR (view renderer + islands) souseTranslation()defaults to the module bundle key namespace. - Extend the Cypress i18n E2E test to validate SSR + hydration behavior with components from two different modules on the same page.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/cypress/e2e/ui/testI18n.cy.ts | Expands E2E coverage to assert SSR + hydrated translations for multiple modules on one page. |
| samples/hydrogen/src/components/LanguageSwitcher/default.server.tsx | Switches server component translation usage to useTranslation() for context-aware SSR. |
| samples/hydrogen/src/components/HelloWorld/default.server.tsx | Switches server component translation usage to useTranslation() for context-aware SSR. |
| javascript-modules-library/src/components/render/Island.tsx | Provides defaultNS={bundleKey} to scope translations correctly within islands during SSR. |
| javascript-modules-engine/src/server/init-react.tsx | Provides defaultNS={bundleKey} during SSR view rendering (and stops mutating global default namespace). |
| javascript-create-module/templates/hello-world/src/components/Hello/World/default.server.tsx | Updates template server component to use useTranslation() to match the new SSR i18n approach. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dgriffon
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #317.
Description
Use
useTranslation()hook in server components: Replaced directimport { t } from "i18next"with usage ofuseTranslation()hook in all React server components (HelloWorld,LanguageSwitcher, etc.). This ensures translations are context-aware and avoid hydration mismatches between server and client.Also, explicitly set the default namespace (
defaultNS) inI18nextProviderwrapper to ensure proper translation loading for multiple modules on the same page. Its value is the bundle key (symbolic name).Testing
Enhance the existing Cypress test with components from multiple JS modules on the same page, to validate:
hydrogenmodule render server-side translationsjavascript-modules-engine-test-modulerender server-side translationsTip
Documentation to guide the reviews: How to do a code review