From ff2ba0aa5ae37c168f9ca31c82219f54e188eec3 Mon Sep 17 00:00:00 2001 From: Alexey Grigorev Date: Mon, 23 Nov 2026 14:13:23 +0100 Subject: [PATCH] Sponsor doc: save-specific NOT SAVED text that never says reload Live check on prod showed a failed autosave reading 'Could not load the document ... Reload the page to try again' - the request layer's generic text. Reloading would throw the unsaved edits away. Timeouts, network errors and 5xx now explain the save failure and point to Retry save. --- backend/e2e/sponsor-doc-utm-save.spec.js | 3 ++- .../src/surfaces/operations/sponsor-doc-autosave.js | 13 +++++++++++++ frontend/test/sponsor-docs.test.mjs | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/e2e/sponsor-doc-utm-save.spec.js b/backend/e2e/sponsor-doc-utm-save.spec.js index a7f59ad6..035f1ef1 100644 --- a/backend/e2e/sponsor-doc-utm-save.spec.js +++ b/backend/e2e/sponsor-doc-utm-save.spec.js @@ -87,7 +87,8 @@ test("a failed autosave shows a loud NOT SAVED error, reports it, and Retry save await page.locator("#sponsor-field-title").fill("Will fail first"); await expect(status(page)).toHaveAttribute("data-sponsor-save-state", "error", { timeout: 10_000 }); await expect(status(page)).toHaveAttribute("role", "alert"); - await expect(status(page)).toContainText("NOT SAVED"); + await expect(status(page)).toContainText("NOT SAVED: the server returned an error (500)"); + await expect(status(page)).not.toContainText("Reload the page"); await expect.poll(() => reports.length).toBeGreaterThan(0); await page.unroute("**/api/sponsor-docs/*", failPut); await page.locator('[data-sponsor-action="retry-save"]').click(); diff --git a/frontend/src/surfaces/operations/sponsor-doc-autosave.js b/frontend/src/surfaces/operations/sponsor-doc-autosave.js index d9b4918b..30ce8a83 100644 --- a/frontend/src/surfaces/operations/sponsor-doc-autosave.js +++ b/frontend/src/surfaces/operations/sponsor-doc-autosave.js @@ -7,7 +7,20 @@ export const SPONSOR_DOC_AUTOSAVE_DELAY_MS = 1200; // (it records a booking intent), so autosave keeps its saved value. const EXPLICIT_SAVE_KEYS = ["slotChoice"]; +/** + * Never tell the visitor to reload after a failed save: a reload throws the + * unsaved edits away. Timeouts, network errors and 5xx (already reported to + * the server by the request layer) get a save-specific explanation. + */ export function notSavedMessage(err) { + const status = err?.status; + let cause; + if (status === "timeout") cause = "the server took too long to respond."; + else if (status === "network") cause = "the connection failed."; + else if (typeof status === "number" && status >= 500) cause = `the server returned an error (${status}).`; + if (cause) { + return `NOT SAVED: ${cause} Your edits are still in this form; do not reload. Click Retry save, or keep editing and it retries. The DataTalks.Club team has been notified.`; + } return `NOT SAVED: ${err?.message || "Failed to save changes."} Your edits are still in this form.`; } diff --git a/frontend/test/sponsor-docs.test.mjs b/frontend/test/sponsor-docs.test.mjs index ce438aa1..f2814ca5 100644 --- a/frontend/test/sponsor-docs.test.mjs +++ b/frontend/test/sponsor-docs.test.mjs @@ -1117,7 +1117,7 @@ test("typing autosaves after the debounce; a failed autosave is loud and Retry s assert.equal(puts[0].content.headline, "Edited"); assert.equal(status().dataset.sponsorSaveState, "error"); assert.equal(status().getAttribute("role"), "alert"); - assert.match(status().textContent, /NOT SAVED: Could not save: it took too long to respond/); + assert.match(status().textContent, /NOT SAVED: the server took too long to respond\. Your edits are still in this form; do not reload/); failPuts = false; await h.root.querySelector('[data-sponsor-action="retry-save"]').click(); await settle();