Files
OpenMAIC/app
John Costaandwyuc 9f6c1419ec fix(i18n): resolve the initial locale on the server so SSR and hydration agree (AI-assisted) (#1874)
* fix(i18n): resolve the initial locale once on the server and hydrate with it

The root layout now picks the UI locale from the locale cookie, then
Accept-Language, then defaultLocale, renders <html lang> with it, and hands
the locale and its bundle to I18nProvider. The client starts from that value
instead of re-detecting, so the first client render matches the server HTML.

setLocale persists the choice to the cookie (and localStorage) immediately,
loads the new bundle, and commits the locale to React state only once the
bundle is in, dropping a slower earlier switch. A failed load keeps the
current locale and restores the previous choice; a later attempt loads
again. The provider keeps its useTranslation subscription so loads still
re-render. A choice stored only in localStorage by earlier versions is
carried over to the cookie once.

Fixes #1445
Fixes #1536

* fix(i18n): refresh the locale cookie and localStorage mirror on load

When the locale cookie matches the server's choice, write it again on
mount so Safari's 7-day cap on script-set cookies doesn't expire it, and
so localStorage.locale (still read by PBL) follows the server's choice.

---------

Co-authored-by: wyuc <wang-yc24@mails.tsinghua.edu.cn>
2026-10-16 15:09:21 +08:00
..