From e8c271d5899f7c79d9604cb5ffa67e88d6f34b40 Mon Sep 17 00:00:00 2001 From: Madraka <8898640+Madraka@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:05:54 +0300 Subject: [PATCH] fix(app): a mailbox's settings are saved when the app holds them Saving a mailbox's settings told its caller it was done and only then read the mailbox again. A person who saved a signature and wrote at once got a window without it, because the window read the copy from before. The save now ends when both lists have been read again. Seen in CI on 2026-11-18. The browser test now holds the answer back for a second: it fails every time without this change and passes with it. Refs #47 Co-Authored-By: Claude Fable 5.2 Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com> --- app/queries/mailboxes.ts | 12 ++++++++---- test/e2e/mailbox.spec.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/queries/mailboxes.ts b/app/queries/mailboxes.ts index 2aefbb2..f1a3b5c 100644 --- a/app/queries/mailboxes.ts +++ b/app/queries/mailboxes.ts @@ -39,10 +39,14 @@ export function useUpdateMailbox() { return useMutation({ mutationFn: ({ mailboxId, settings }: { mailboxId: string; settings: unknown }) => api.updateMailbox(mailboxId, settings), - onSuccess: (_data, { mailboxId }) => { - qc.invalidateQueries({ queryKey: queryKeys.mailboxes.detail(mailboxId) }); - qc.invalidateQueries({ queryKey: queryKeys.mailboxes.all }); - }, + // The save is over when the app holds what was saved: the two lists are read again before + // the caller is told. Told earlier, a person who saved a signature and wrote at once got a + // message without it. + onSuccess: (_data, { mailboxId }) => + Promise.all([ + qc.invalidateQueries({ queryKey: queryKeys.mailboxes.detail(mailboxId) }), + qc.invalidateQueries({ queryKey: queryKeys.mailboxes.all }), + ]), }); } diff --git a/test/e2e/mailbox.spec.ts b/test/e2e/mailbox.spec.ts index 22f6978..d935a49 100644 --- a/test/e2e/mailbox.spec.ts +++ b/test/e2e/mailbox.spec.ts @@ -656,9 +656,23 @@ test("settings are in tabs; a person's choices take effect at once and stay, a m await page.getByLabel("Add a signature to new messages").check(); await page.locator(".ProseMirror").click(); await page.keyboard.type("Kind regards from the pod bay"); + // The app reads the mailbox again after a save. That answer is held back here, so that + // "saved" said before it arrived would open a window without the signature. + const held: Promise[] = []; + const mailboxRead = (url: URL) => /^\/api\/v1\/mailboxes(\/[^/]+)?$/.test(url.pathname); + await page.route(mailboxRead, (route) => { + if (route.request().method() !== "GET") return route.continue(); + const answered = new Promise((resolve) => setTimeout(resolve, 1000)).then(() => + route.continue(), + ); + held.push(answered); + return answered; + }); await page.getByRole("button", { name: "Save signature" }).click(); await expect(page.getByText("Signature saved")).toBeVisible(); await page.getByRole("button", { name: "Compose" }).click(); + await Promise.all(held); + await page.unroute(mailboxRead); const compose = page.getByRole("region", { name: "Compose" }); await expect(compose.locator(".ProseMirror")).toContainText("Kind regards from the pod bay"); await compose.getByRole("button", { name: "Discard" }).click();