Skip to content

🗣️ fix: Prevent @librechat/client useLocalize from Overwriting Host App Language State#12515

Merged
danny-avila merged 3 commits into
danny-avila:devfrom
shtayeb:fix/languge-flicker-inconsistent-lang-init
Apr 3, 2026
Merged

🗣️ fix: Prevent @librechat/client useLocalize from Overwriting Host App Language State#12515
danny-avila merged 3 commits into
danny-avila:devfrom
shtayeb:fix/languge-flicker-inconsistent-lang-init

Conversation

@shtayeb

@shtayeb shtayeb commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

langAtom is hardcoded to en in packages/client/src/store.ts
in comparison with the main app's client/src/hooks/useLocalize.ts which reads from real sources in client/src/store/language.ts

Both hooks call i18n.changeLanguage() on the same i18next singleton. When the packages/client hook fires first with 'en', it overwrites the language before the main app hook can correct it.


(look at value of i18nextLng in localstorage)

Screen.Recording.2026-04-02.at.0.16.31.PM.mov

Change Type

  • Bug fix (non-breaking change which fixes an issue)

How the bug plays out

  1. User visits /d/new with language set to e.g., fr
  2. Opens settings dialog, which imports components from @librechat/client (e.g., Button, Input, Select)
  3. Some of these components use useLocalize from packages/client/src/hooks/useLocalize.ts
  4. That hook reads langAtom'en' (hardcoded default)
  5. Since i18n.language (detected as fr) !== 'en', it calls i18n.changeLanguage('en')
  6. This writes i18nextLng = 'en' to localStorage. the user sees the flicker to English(not very visible in the dialog case but can be worse when you are fetching data and have to wait for the result)
  7. The main app's(client/) useLocalize (from client/src/hooks/useLocalize.ts) reads the Recoil atom (fr) and calls i18n.changeLanguage('fr') fixing it back since no data is fetched it happens fast.
  8. On second visit, i18nextLng is already fr from step 7, so i18n.language matches langAtom... wait, no, langAtom is still 'en'

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code

Proposed fix

It removes the language overwrite from packages/client/src/hooks/useLocalize.ts hook and only read it.

Alt fix: initialize langAtom from actual language sources.

Note: If there is any reason for keeping it as it is, please let me know.

@danny-avila danny-avila changed the title Fix: language flicker caused by inconsistencies in useLocalize hook in main client/ and packages/client 🗣️ fix: Prevent @librechat/client useLocalize from Overwriting Host App Language State Apr 3, 2026
@danny-avila
danny-avila changed the base branch from main to dev April 3, 2026 18:07
@danny-avila
danny-avila force-pushed the fix/languge-flicker-inconsistent-lang-init branch from a077c3d to 873c6f7 Compare April 3, 2026 18:58
@danny-avila
danny-avila merged commit 2140729 into danny-avila:dev Apr 3, 2026
9 checks passed
yidianyiko pushed a commit to yidianyiko/LibreChat that referenced this pull request Apr 13, 2026
… App Language State (danny-avila#12515)

* directly returns the translation function without managing language state in client package

* chore: remove unused langAtom from packages/client store

* fix: add useCallback to match canonical useLocalize, add guard comment

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
… App Language State (danny-avila#12515)

* directly returns the translation function without managing language state in client package

* chore: remove unused langAtom from packages/client store

* fix: add useCallback to match canonical useLocalize, add guard comment

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
… App Language State (danny-avila#12515)

* directly returns the translation function without managing language state in client package

* chore: remove unused langAtom from packages/client store

* fix: add useCallback to match canonical useLocalize, add guard comment

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants