fix(i18n): deterministic first render — no hydration mismatch for non-English users
Fixes the console error Kiet hit on docs: Hydration failed because the server rendered text didn't match the client — server Search docs..., client Tìm trong tài liệu....
Mechanism: module-scope activation inferred the locale in the browser (cookie/navigator) before React hydrated, so the client's first render was localized while the server had rendered the default. Every translated client-component string mismatched for every non-English user — the same class the production review measured as React #418s clustering on ja/ru/tr.
Fix: module scope activates the default locale — identical on server and client — and the provider switches to the inferred or chosen locale after mount (existing effect + keyed remount). Trade-off stated plainly: a brief default-language flash on client chrome for non-en users; content on marketing is RSC-localized in the served HTML and never hydrates, so what search engines and first paint see is unchanged. This is the standard resolution for statically-served client components (docs).
i18n tests 116/116.
https://claude.ai/code/session_012U97YWVsDvZwQkBaSGEmor
Summary by cubic
Fixes the hydration mismatch that threw Hydration failed because the server rendered text didn't match the client for non-English users. The first client render now uses the same default locale as the server, and the provider switches to the inferred or chosen locale after mount.
Non-English users will see a brief default-language flash on client chrome. Marketing content is RSC-localized in the served HTML and never hydrates, so search engine and first-paint content are unchanged.
Summary by CodeRabbit
- Bug Fixes
- Improved localization consistency between server-rendered content and the client’s initial display.
- Locale detection and explicit locale selection now occur after the application loads, reducing potential rendering mismatches.