Stop a language change undoing itself, and stop the translate prompt

Two reports, both about the language setting.

**Picking a language sometimes took several clicks.** The subtree that
reads the account's settings file is keyed on the language version, so
choosing a language deliberately throws it away and builds it again. The
remount re-read the settings file — which still held the old language,
because the write is debounced by three seconds — and applied it, putting
the old language back. The click that appeared to work was the one made
after the previous write had landed, which is exactly the "sometimes"
in the report.

Worse than it looked: the queued push survived the remount, so the file
was eventually written with the new language while the screen showed the
old one. A reload then changed the language on its own.

Fixed twice over, because either alone leaves a race. The file is read
once per account per page load rather than once per mount, and hydrate
now holds back any key with a change still queued — a change that has
not been written up is newer than the file by definition. That rule is
`mergeRemote`, pulled out as a pure function so it could be tested
without a JMAP client.

**Both browsers kept offering to translate an English page.** They were
right to: `<html lang>` said English while the visible text was 6,289
message rows of marketing copy and brand names in whatever language the
sender wrote in. The list is most of the text on the screen, so that is
what the detector was reading.

Sender, subject and preview in the list, and the thread subject and
sender name in the reader, are now marked as what they are — content,
not interface. Message bodies were already marked, so this is the same
line drawn in the places the earlier pass missed rather than a new one.
Whether it silences the prompt is Chrome's call and cannot be checked
from inside the page; the marking is right either way.
This commit is contained in:
2026-08-31 13:45:18 -07:00
parent a4f7d386a6
commit 51dabd9cab
7 changed files with 117 additions and 13 deletions
+46 -1
View File
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_SETTINGS, DEVICE_KEYS, acceptRemote, syncedPart, type Settings } from "@/store/settings";
import { DEFAULT_SETTINGS, DEVICE_KEYS, acceptRemote, mergeRemote, syncedPart, type Settings } from "@/store/settings";
import { isAppFolder } from "../appFolder";
import { settingsAlreadyLoadedFor, stopSettingsSync } from "../settingsSync";
/**
* Settings used to live only in localStorage, so nothing followed the user
@@ -81,3 +82,47 @@ describe("the client's own folder", () => {
expect(isAppFolder({ name: "ihasmail", parentId: null, nodeType: "file" })).toBe(false);
});
});
/**
* Picking a language used to come undone.
*
* The subtree that reads the account's settings file is keyed on the language
* version, so choosing a language throws it away and builds it again. The
* remount re-read the file — which still held the old language, because the
* write is debounced by three seconds — and applied it, putting the old
* language back. Reported as "sometimes it takes several clicks": the click
* that appeared to work was the one made after the previous write had landed.
*/
describe("a change made but not yet written up", () => {
it("is not read back over by the file it has not reached yet", () => {
const current: Settings = { ...DEFAULT_SETTINGS, uiLanguage: "ja" };
const file = { uiLanguage: "en", theme: "dark" };
const merged = mergeRemote(current, file, new Set(["uiLanguage"]));
expect(merged.uiLanguage).toBe("ja");
// Only the queued key is held back; the rest of the file still applies.
expect(merged.theme).toBe("dark");
});
it("applies the whole file when nothing is queued", () => {
const current: Settings = { ...DEFAULT_SETTINGS, uiLanguage: "ja" };
const merged = mergeRemote(current, { uiLanguage: "en" });
expect(merged.uiLanguage).toBe("en");
});
it("reads the file again for an account after a sign-out", () => {
stopSettingsSync();
expect(settingsAlreadyLoadedFor("a1")).toBe(false);
// The remount that a language change causes must not read it a second time.
expect(settingsAlreadyLoadedFor("a1")).toBe(true);
// Signing out drops the claim, so signing back in reads the file rather
// than trusting whatever the previous session left behind.
stopSettingsSync();
expect(settingsAlreadyLoadedFor("a1")).toBe(false);
stopSettingsSync();
});
it("treats a missing account as already loaded, so nothing is fetched", () => {
expect(settingsAlreadyLoadedFor(null)).toBe(true);
expect(settingsAlreadyLoadedFor(undefined)).toBe(true);
});
});