diff --git a/apps/desktop/src/i18n/__tests__/localePreview.spec.ts b/apps/desktop/src/i18n/__tests__/localePreview.spec.ts
new file mode 100644
index 0000000000..4a7c28d760
--- /dev/null
+++ b/apps/desktop/src/i18n/__tests__/localePreview.spec.ts
@@ -0,0 +1,85 @@
+// @vitest-environment happy-dom
+
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { currentLocale, previewLocale, restoreLocalePreview, setLocale } from "@/i18n";
+
+const delayedItalianLocale = vi.hoisted(() => {
+ let resolveLocaleModule: ((module: { default: Record }) => void) | undefined;
+ let pendingLocaleModule: Promise<{ default: Record }>;
+
+ function reset() {
+ pendingLocaleModule = new Promise((resolve) => {
+ resolveLocaleModule = resolve;
+ });
+ }
+
+ reset();
+
+ return {
+ reset,
+ load: () => pendingLocaleModule,
+ resolve: () => resolveLocaleModule?.({ default: {} }),
+ };
+});
+
+vi.mock("@/i18n/locales/it", () => delayedItalianLocale.load());
+
+describe("locale preview", () => {
+ beforeEach(async () => {
+ delayedItalianLocale.reset();
+ await setLocale("en");
+ window.localStorage.clear();
+ });
+
+ afterEach(async () => {
+ await setLocale("en");
+ window.localStorage.clear();
+ vi.restoreAllMocks();
+ });
+
+ it("changes the visible locale without persisting a hover preview", async () => {
+ const setItem = vi.spyOn(window.localStorage, "setItem");
+
+ await previewLocale("es");
+
+ expect(currentLocale()).toBe("es");
+ expect(setItem).not.toHaveBeenCalled();
+
+ await restoreLocalePreview();
+ expect(currentLocale()).toBe("en");
+ expect(setItem).not.toHaveBeenCalled();
+ });
+
+ it("keeps the most recent asynchronous preview", async () => {
+ const firstPreview = previewLocale("zh-CN");
+ const latestPreview = previewLocale("ja");
+
+ await Promise.all([firstPreview, latestPreview]);
+
+ expect(currentLocale()).toBe("ja");
+ await restoreLocalePreview();
+ expect(currentLocale()).toBe("en");
+ });
+
+ it("restores a selected locale when closing its list before loading finishes", async () => {
+ const selected = setLocale("ko");
+ const restore = restoreLocalePreview();
+
+ await Promise.all([selected, restore]);
+
+ expect(currentLocale()).toBe("ko");
+ expect(window.localStorage.getItem("dbx-locale")).toBe("ko");
+ });
+
+ it("persists an explicit choice before its delayed messages become visible", async () => {
+ const selected = setLocale("it");
+
+ expect(window.localStorage.getItem("dbx-locale")).toBe("it");
+ expect(currentLocale()).toBe("en");
+
+ delayedItalianLocale.resolve();
+ await selected;
+
+ expect(currentLocale()).toBe("it");
+ });
+});
diff --git a/apps/desktop/src/i18n/index.ts b/apps/desktop/src/i18n/index.ts
index 1e47b7491a..026d1f37a0 100644
--- a/apps/desktop/src/i18n/index.ts
+++ b/apps/desktop/src/i18n/index.ts
@@ -72,6 +72,8 @@ function detectUserLocale(): Locale {
const savedLocale = normalizeLocale(safeLocalStorageGet("dbx-locale"));
const initialLocale = savedLocale ?? detectUserLocale();
+let persistedLocale = initialLocale;
+let localeRequestId = 0;
const i18n = createI18n({
legacy: false,
@@ -107,11 +109,37 @@ export async function loadSavedLocale() {
void syncLocaleToBackend(initialLocale);
}
-export async function setLocale(locale: Locale) {
+async function applyTransientLocale(locale: Locale) {
+ const requestId = ++localeRequestId;
await loadLocaleMessages(locale);
+ if (requestId !== localeRequestId) return;
i18nGlobal.locale.value = locale;
+}
+
+// Temporary previews deliberately skip persistence and backend synchronization.
+// The request id makes a slow locale import unable to overwrite a newer hover,
+// a restore, or an explicitly selected locale.
+export async function previewLocale(locale: Locale) {
+ await applyTransientLocale(locale);
+}
+
+export async function restoreLocalePreview() {
+ await applyTransientLocale(persistedLocale);
+}
+
+export async function setLocale(locale: Locale) {
+ // Record a user selection before awaiting a lazy locale import. A following
+ // close/restore must use the selected locale rather than an older preview.
+ persistedLocale = locale;
+ ++localeRequestId;
+ // An explicit selection is durable immediately; only the visible locale
+ // waits for its lazy message bundle. Preview paths never reach this branch.
safeLocalStorageSet("dbx-locale", locale);
void syncLocaleToBackend(locale);
+ await loadLocaleMessages(locale);
+ // A later explicit selection wins; hover/restore requests must not undo it.
+ if (persistedLocale !== locale) return;
+ i18nGlobal.locale.value = locale;
}
export function currentLocale(): Locale {
diff --git a/apps/desktop/src/lib/app/__tests__/uiScaleApplyQueue.spec.ts b/apps/desktop/src/lib/app/__tests__/uiScaleApplyQueue.spec.ts
new file mode 100644
index 0000000000..f7679249f1
--- /dev/null
+++ b/apps/desktop/src/lib/app/__tests__/uiScaleApplyQueue.spec.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it, vi } from "vitest";
+import { createUiScaleApplyQueue } from "@/lib/app/uiScaleApplyQueue";
+
+function deferred() {
+ let resolve: (() => void) | undefined;
+ return {
+ promise: new Promise((done) => {
+ resolve = done;
+ }),
+ resolve: () => resolve?.(),
+ };
+}
+
+describe("ui scale apply queue", () => {
+ it("serializes zoom IPC and only publishes the newest completed target", async () => {
+ const first = deferred();
+ const latest = deferred();
+ const apply = vi.fn((scale: number) => (scale === 0.75 ? first.promise : latest.promise));
+ const applied = vi.fn();
+ const queue = createUiScaleApplyQueue(apply, applied, vi.fn());
+
+ queue.request(0.75);
+ queue.request(1.25);
+ expect(apply).toHaveBeenCalledTimes(1);
+ expect(apply).toHaveBeenLastCalledWith(0.75);
+
+ first.resolve();
+ await Promise.resolve();
+ expect(apply).toHaveBeenCalledTimes(2);
+ expect(apply).toHaveBeenLastCalledWith(1.25);
+ expect(applied).not.toHaveBeenCalled();
+
+ latest.resolve();
+ await queue.whenIdle();
+
+ expect(applied).toHaveBeenCalledTimes(1);
+ expect(applied).toHaveBeenCalledWith(1.25);
+ });
+});
diff --git a/apps/desktop/src/lib/app/uiScaleApplyQueue.ts b/apps/desktop/src/lib/app/uiScaleApplyQueue.ts
new file mode 100644
index 0000000000..27b626d9ef
--- /dev/null
+++ b/apps/desktop/src/lib/app/uiScaleApplyQueue.ts
@@ -0,0 +1,65 @@
+export interface UiScaleApplyQueue {
+ request: (scale: number) => void;
+ whenIdle: () => Promise;
+}
+
+export function createUiScaleApplyQueue(apply: (scale: number) => Promise, onApplied: (scale: number) => void, onError: (scale: number, error: unknown) => void): UiScaleApplyQueue {
+ let queuedScale: number | undefined;
+ let applying = false;
+ let lastAppliedScale: number | undefined;
+ let idleResolvers: Array<() => void> = [];
+
+ function resolveIdle() {
+ if (applying || queuedScale !== undefined) return;
+ const resolvers = idleResolvers;
+ idleResolvers = [];
+ resolvers.forEach((resolve) => resolve());
+ }
+
+ async function flush() {
+ try {
+ while (queuedScale !== undefined) {
+ const scale = queuedScale;
+ queuedScale = undefined;
+ if (scale === lastAppliedScale) continue;
+
+ try {
+ await apply(scale);
+ } catch (error) {
+ onError(scale, error);
+ continue;
+ }
+
+ // Newer requests replace this completed IPC result. Repeating the same
+ // scale is already satisfied by this call, so coalesce it as well.
+ if (queuedScale === undefined || queuedScale === scale) {
+ queuedScale = undefined;
+ lastAppliedScale = scale;
+ onApplied(scale);
+ }
+ }
+ } finally {
+ applying = false;
+ if (queuedScale !== undefined) {
+ applying = true;
+ void flush();
+ } else {
+ resolveIdle();
+ }
+ }
+ }
+
+ function request(scale: number) {
+ queuedScale = scale;
+ if (applying) return;
+ applying = true;
+ void flush();
+ }
+
+ function whenIdle() {
+ if (!applying && queuedScale === undefined) return Promise.resolve();
+ return new Promise((resolve) => idleResolvers.push(resolve));
+ }
+
+ return { request, whenIdle };
+}
diff --git a/apps/desktop/src/lib/common/__tests__/searchableSelectLayout.spec.ts b/apps/desktop/src/lib/common/__tests__/searchableSelectLayout.spec.ts
index 8c41e97c93..838f763146 100644
--- a/apps/desktop/src/lib/common/__tests__/searchableSelectLayout.spec.ts
+++ b/apps/desktop/src/lib/common/__tests__/searchableSelectLayout.spec.ts
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const searchableSelectSource = readFileSync(new URL("../../../components/ui/searchable-select/SearchableSelect.vue", import.meta.url), "utf8");
+const editorSettingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
const dataTransferDialogSource = readFileSync(new URL("../../../components/transfer/DataTransferDialog.vue", import.meta.url), "utf8");
const editorToolbarSource = readFileSync(new URL("../../../components/layout/EditorToolbar.vue", import.meta.url), "utf8");
const schemaDiffConfigStepSource = readFileSync(new URL("../../../components/diff/SchemaDiffConfigStep.vue", import.meta.url), "utf8");
@@ -20,6 +21,15 @@ describe("SearchableSelect layout", () => {
expect(searchableSelectSource).toContain("props.trimCustom ? searchText.value.trim() : searchText.value");
});
+ it("forwards an optional style to its portaled content for local preview isolation", () => {
+ expect(searchableSelectSource).toContain('contentStyle?: HTMLAttributes["style"]');
+ expect(searchableSelectSource).toContain(':style="contentStyle"');
+ expect(editorSettingsDialogSource).toContain(':content-style="{ fontFamily: editUiFontFamily || DEFAULT_UI_FONT_FAMILY }"');
+ expect(editorSettingsDialogSource).toContain('@option-hover="previewUiFontOption"');
+ expect(editorSettingsDialogSource).toContain('@option-highlight="previewUiFontOption"');
+ expect(editorSettingsDialogSource).toContain('@option-leave="restoreUiFontFamilyPreview"');
+ });
+
it("renders data transfer connection pickers as sidebar-like trees", () => {
const treeSelects = dataTransferDialogSource.match(/