fix: 欢迎页语言切换器无效 #448#1148
Conversation
修复bootstrapLocale函数race condition问题,当用户通过localStorage手动选择语言时,尊重用户选择,不覆盖现有设置。 - 修改文件: apps/web/src/hooks/use-locale.tsx - 新增逻辑: 在bootstrap过程中检查localStorage中的用户手动选择 - 修复问题: 欢迎页语言切换器无法改变UI语言的问题
lefarcen
left a comment
There was a problem hiding this comment.
Hi @masher-pp! 🎉
Wow, excellent fix for the welcome page locale switcher—what a thoughtful solution to the race condition! 🙌 Respecting localStorage user preferences is exactly the right approach, and the try-catch for safe access + precise validation (only 'en'/'zh') shows great attention to detail.
A few quick thoughts:
- Consider adding a comment above the try-catch explaining the localStorage check's purpose (helps future maintainers understand the #448 fix context).
- The catch-all
/* ignore */works, butcatch (e) { console.warn('localStorage locale read failed:', e); }would help debug storage-disabled scenarios without blocking.
This looks solid overall! We'll review promptly (target: 24h). Questions or updates? Push here!
Join communities:
- Feishu: https://applink.feishu.cn/client/chat/chatter/add_by_link?link_token=90emc2e9-86cd-4723-b455-ca41b70f162d
- Discord: https://discord.gg/nexu
Thanks for making Nexu better!
Nexu Team
| // user-selected English back to Chinese on the welcome screen. | ||
| // Issue #448: the welcome page language switcher does not change UI language | ||
| // because the bootstrap was overwriting the user's selection. | ||
| if (userInteractedRef.current) { |
There was a problem hiding this comment.
Consider adding a JSDoc comment here explaining this localStorage check fixes #448 by preventing bootstrap from overwriting user manual selection. Helps future readers.
| return; | ||
| } | ||
|
|
||
| // If the user has manually selected a language via localStorage, use that |
There was a problem hiding this comment.
Optional: More explicit catch for debugging, e.g. catch (e) { console.warn('Failed to read locale from localStorage:', e); } - doesn't block but surfaces issues in devtools if storage is quota-exceeded/disabled.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 323edbd204
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (manualSelection === "en" || manualSelection === "zh") { | ||
| // User has manually selected a language, respect their choice | ||
| return; |
There was a problem hiding this comment.
Sync desktop locale before returning on local selection
Returning immediately when localStorage has en/zh skips the bootstrap sync path entirely, so the controller-side locale can stay stale (or null) indefinitely. A concrete case is: initial GET /internal/desktop-preferences fails once, localStorage is populated locally, and on later successful boots this early return prevents syncDesktopLocale(...) from ever running, leaving backend locale-dependent behavior (for example credit-guard/message localization) out of sync with the UI language.
Useful? React with 👍 / 👎.
问题�ootstrapLocale 存在 race condition,当用户通过 localStorage 手动选择语言时,会被覆盖为系统默认语言,导致欢迎页语言切换器无法改变 UI 语言。## 修复- 在 �ootstrapLocale 过程中检查 localStorage 中的用户手动选择- 尊重用户选择,不覆盖现有设置## 关联Fixes #448