Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/lib/lang.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const langMap = {

Check failure on line 1 in src/lib/lang.js

View workflow job for this annotation

GitHub Actions / Linting and formatting

format

File content differs from formatting output
"en-us": {
name: "English",
async strings() {
Expand Down Expand Up @@ -190,9 +190,10 @@
export default {
async set(code) {
code = code?.toLowerCase();
const lang = langMap[code] || langMap["en-us"];
const lang = langMap[code] || langMap[code = "en-us"];
const strings = await lang.strings();
window.strings = strings.default;
window.localStorage["language"] = code;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Stale Language Wins Race

When settings.applyLangSetting() fires lang.set(value) without awaiting it, two quick language changes can resolve out of order. The older lang.strings() import can finish last and this line then persists the stale code, so the next startup can restore a language different from the user's latest selection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Storage Failure Leaves Split State

When storage is unavailable or throws, this new write rejects after window.strings has already been updated. The settings-change path does not await lang.set(value), so the saved setting, in-memory strings, and persisted language value can diverge without the caller seeing the failure.

Comment on lines +193 to +196

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Fallback Overwrites Requested Code

For an unsupported input such as a fresh-install navigator.language value of en or es, the fallback expression rewrites code to en-us before the new persistence step. That stores the fallback instead of the requested language code, so anything reading localStorage["language"] loses the original browser/user language value.

},
list: Object.keys(langMap).map((code) => [code, langMap[code].name]),
getName(code) {
Expand Down
Loading