Repository navigation
fix(share): The language of the shared page will cause the language of the original website to change. - #18043
Conversation
…rage - Add `persist` option to `changeLanguageAsync` to skip writing language to localStorage - Pass `persist: false` on share pages (chat/agent/search) and floating widget so the visitor's main site language setting isn't overwritten - Fix `SelectWithSearch` using non-reactive `t` from `i18next` — switch to `useTranslation()` so dropdown placeholders and empty state update on language change - Remove unnecessary `useMemo` wrapping on `thinkingOptions` in `NextMessageInput` — `t` ref is stable so memoization prevented label updates after `changeLanguage` - Remove duplicate language init effect from `RootProvider` (already handled in `main.tsx` via `initLanguage`) Co-Authored-By: Claude Opus 4.6 <[email protected]>
📝 WalkthroughWalkthroughThe update makes language persistence optional, disables persistence for temporary locale changes, removes startup language restoration, and resolves select translations during rendering. It also removes memoization from the thinking options list. ChangesLocale persistence and initialization
Render-time translation updates
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
wangq8
left a comment
There was a problem hiding this comment.
Thanks for this fix! The root cause analysis is solid — shared pages overwriting the main site language preference is a real UX issue, and your persist option approach is clean and backward-compatible.
What looks good:
changeLanguageAsyncwithpersistoption (defaulttrue) is a minimal, non-breaking API change. All callers that don't passpersistkeep existing behavior.- The
persist: falseadditions on share pages (agent/share, chats/share, search/share, floating widget) correctly scope the fix to the affected surfaces. - Removing the duplicate language init from
RootProvideris correct —initLanguageinmain.tsxalready handles this, and having both creates a race. - The
SelectWithSearchfix switching fromimport { t } from i18next(module-level, non-reactive) touseTranslation()(hook, reactive) is exactly right. Without it, default placeholders and empty states would be stuck in the initial language.
One note on NextMessageInput:
- Removing
useMemofromthinkingOptionsis the right call sincetfromuseTranslation()is reference-stable, so the memo was equivalent touseMemo(() => [...], [])— it would never update on language change. - Now
thinkingOptionsis recreated on every render. The translated strings are the same-by-value but different-by-reference each time. If the selector component does reference-equality checks on the options array, it could trigger extra re-renders. In practice, this is a minor concern for a thinking-level dropdown — not a perf hotspot. Just something to be aware of.
Overall LGTM. Nice work!
Summary
fix(share): The language of the shared page will cause the language of the original website to change.
persistoption tochangeLanguageAsyncto skip writing language to localStoragepersist: falseon share pages (chat/agent/search) and floating widget so the visitor's main site language setting isn't overwrittenSelectWithSearchusing non-reactivetfromi18next— switch touseTranslation()so dropdown placeholders and empty state update on language changeuseMemowrapping onthinkingOptionsinNextMessageInput—tref is stable so memoization prevented label updates afterchangeLanguageRootProvider(already handled inmain.tsxviainitLanguage)