Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/web/src/hooks/use-locale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,24 @@ async function bootstrapLocale(
// flight, their selection is the source of truth — don't overwrite it.
// Issue #759: on Windows zh-CN systems, the bootstrap was reverting a
// 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.

// as the source of truth and don't overwrite it with the server value.
try {
const manualSelection = localStorage.getItem(STORAGE_KEY);
if (manualSelection === "en" || manualSelection === "zh") {
// User has manually selected a language, respect their choice
return;
Comment on lines +127 to +129
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 👍 / 👎.

}
} catch {
/* ignore */
}

if (storedLocale === "en" || storedLocale === "zh-CN") {
const nextLocale = storedLocale === "zh-CN" ? "zh" : "en";
await i18n.changeLanguage(nextLocale);
Expand Down