Skip to content

fix: 欢迎页语言切换器无效 #448#1148

Open
masher-pp wants to merge 1 commit intonexu-io:mainfrom
masher-pp:fix-pure-448
Open

fix: 欢迎页语言切换器无效 #448#1148
masher-pp wants to merge 1 commit intonexu-io:mainfrom
masher-pp:fix-pure-448

Conversation

@masher-pp
Copy link
Copy Markdown

问题�ootstrapLocale 存在 race condition,当用户通过 localStorage 手动选择语言时,会被覆盖为系统默认语言,导致欢迎页语言切换器无法改变 UI 语言。## 修复- 在 �ootstrapLocale 过程中检查 localStorage 中的用户手动选择- 尊重用户选择,不覆盖现有设置## 关联Fixes #448

修复bootstrapLocale函数race condition问题,当用户通过localStorage手动选择语言时,尊重用户选择,不覆盖现有设置。

- 修改文件: apps/web/src/hooks/use-locale.tsx
- 新增逻辑: 在bootstrap过程中检查localStorage中的用户手动选择
- 修复问题: 欢迎页语言切换器无法改变UI语言的问题
@lefarcen lefarcen self-assigned this Apr 18, 2026
Copy link
Copy Markdown
Collaborator

@lefarcen lefarcen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, but catch (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:

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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +127 to +129
if (manualSelection === "en" || manualSelection === "zh") {
// User has manually selected a language, respect their choice
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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