From 98871f9f02f85e7b31becb05096d7a2671dade0b Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 24 Oct 2026 17:38:27 +0200 Subject: [PATCH 1/2] test(e2e): a Settings popout change is on disk once the popout has closed The spec polled data.json for 3 s after the popout closed. The write waits on a 1 s debounce on the main window's timer, which the OS throttles while that window is hidden, so under load it often landed later (#2213). Assert instead that the change is pending when the popout closes and on disk once the write that closing starts has finished. Refs #2213 --- tests/e2e/settings-popout-save.test.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/e2e/settings-popout-save.test.ts b/tests/e2e/settings-popout-save.test.ts index 2c58b08c0..a480f03ba 100644 --- a/tests/e2e/settings-popout-save.test.ts +++ b/tests/e2e/settings-popout-save.test.ts @@ -8,8 +8,7 @@ import { setFocusEmulation, setVaultConfig } from "./uiHelpers"; const getContext = createQuickAddE2EHarness("settings-popout-save"); -// A change made in the Settings popout is saved after the popout closes right after it (#2182): -// the debounced settings write must not be scheduled on the popout window. +// A change made in the Settings popout is saved when the popout closes right after it (#2182, #2213). for (const mainWindow of ["visible", "hidden"] as const) { it(`saves a reorder made in the Settings popout that closes right after, main window ${mainWindow}`, async () => { const { obsidian, plugin } = getContext(); @@ -26,7 +25,7 @@ for (const mainWindow of ["visible", "hidden"] as const) { const popout = await obsidian.dev.evalJson("app.vault.getConfig('settingsPopoutWindow') ?? true"); try { // Reorder by a native mouse drag in the popout, and close it 300 ms after the drop. - const inMemory = await obsidian.dev.evalJsonAsync(`(async () => { + const { order: inMemory, pendingAtClose } = await obsidian.dev.evalJsonAsync<{ order: string[]; pendingAtClose: boolean }>(`(async () => { const remote = require("@electron/remote"); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); ${setVaultConfig("settingsPopoutWindow", true)}; @@ -69,13 +68,20 @@ for (const mainWindow of ["visible", "hidden"] as const) { await popoutSleep(${mainWindow === "hidden" ? 2500 : 300}); contents.sendInputEvent({ type: "mouseUp", x: to.x, y: to.y, button: "left", clickCount: 1 }); await popoutSleep(300); - const order = app.plugins.plugins.quickadd.settings.choices.map((choice) => choice.name); + const plugin = app.plugins.plugins.quickadd; + const order = plugin.settings.choices.map((choice) => choice.name); + const pendingAtClose = plugin.pendingSave !== null; app.setting.close(); - return order; + // The write that closing started. + await plugin.persistChain; + return { order, pendingAtClose }; })()`); expect(inMemory).not.toEqual(["Alpha", "Bravo", "Charlie"]); - // The write is debounced by 1 s, and a hidden window's timers run about once a second. - await expect.poll(onDisk, { timeout: 3000, interval: 250 }).toEqual(inMemory); + // Otherwise the debounce wrote it already, and closing proves nothing. + expect(pendingAtClose).toBe(true); + // Closing settings writes the change, rather than leaving it to a + // debounce on the main window's timer, which a hidden window throttles. + expect(onDisk()).toEqual(inMemory); } finally { await obsidian.dev.evalJson(`(() => { require("@electron/remote").getCurrentWindow().show(); From 8daa994d2d05c3bb89a9e11133f0cab7b142d906 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 24 Oct 2026 17:38:27 +0200 Subject: [PATCH 2/2] fix(settings): write pending settings when Settings closes A settings change is written by a 1 s debounce on the main window's timer. While a Settings popout covers a hidden main window, the OS throttles that timer, and under load the write landed seconds late, once more than 15 s. Closing Settings now writes the pending change at once. Fixes #2213 --- src/main.ts | 2 +- src/quickAddSettingsTab.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index ac505ce67..ec20d038b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -341,7 +341,7 @@ export default class QuickAdd extends Plugin { * Start the pending debounced settings write now. Returns the queued * settings work, or null when there is none to wait for. */ - private flushPendingSave(): Promise | null { + flushPendingSave(): Promise | null { this.requestSave.run(); return this.persistChain; } diff --git a/src/quickAddSettingsTab.ts b/src/quickAddSettingsTab.ts index f036203f8..b90e0995d 100644 --- a/src/quickAddSettingsTab.ts +++ b/src/quickAddSettingsTab.ts @@ -264,6 +264,10 @@ export class QuickAddSettingsTab extends PluginSettingTab { // net for the two Svelte mounts. super.hide(); this.destroySettingViews(); + // Closing settings is when a change is done. The pending write waits on + // the main window's timer, which the OS throttles while that window is + // hidden behind a Settings popout. + void this.plugin.flushPendingSave(); } private destroySettingViews(): void {