DEV Community

Cover image for Your SaaS Says “Saved”? Refresh the Page.
Oleksandr Sainchuk
Oleksandr Sainchuk

Posted on

Your SaaS Says “Saved”? Refresh the Page.

A client of ours vibe-coded their product with AI tools and brought it to a demo. The forms worked, the screens looked finished, and the app said Saved after every action. During that demo it turned out the data had never been stored.

Nothing on the screen hinted at it. From the user's side it looks like this. You type a task, press Save, the task appears in the list, the input clears, and a small green "Saved" shows up under the form. Then you refresh the page and the task is gone, because the server never stored it.

The task appears with a Saved message, then disappears after a page refresh

A false success state is a screen that tells the user an action worked before the server confirmed it, or after the server refused it. This article grew out of that demo. When I review a save flow now, I don't take the green message as proof. I create the record through the UI, reload the page, read the record back through the authenticated API, try the same ID as a different user, and then break the request on purpose to see what the UI says.

checks

To show all four, I built a small React app with an Express API, SQLite and Playwright, then broke it in three different ways. The results surprised me a little. A server that answered 201 and wrote nothing passed the test for failed saves, and a server that leaked tasks between users passed both persistence tests. Every bug got past at least one check, so a single test was never enough.

People write these bugs by hand too. With AI-built features the risk is higher, because an agent can produce a whole flow in minutes and it's easy to accept code you haven't read line by line.

The handler that lies

This is the broken path in the React app. It runs inside the form's submit handler.

setTasks((rows) => [...rows, { id: crypto.randomUUID(), title }]);
setStatus("Saved");
setTitle("");

fetch("/api/tasks", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ title }),
}).catch(() => {});
Enter fullscreen mode Exit fullscreen mode

React adds the row right away, the API answers 503 and writes nothing, and the UI never looks at the answer.

Two things go wrong here. Saved appears before the request finishes, and the code never checks the HTTP status. As MDN explains, fetch() resolves on a 503 the same way it resolves on a 200, so the .catch() fires only for network errors and the 503 goes by unnoticed.

Showing a pending task right away is a fair design choice. The trouble starts when that pending row gets the word Saved, because at that moment the app is confirming something it never checked.

For this small app I picked a simpler contract. The text stays in the input while the request is in flight, the row appears after the server confirms the write, and if confirmation fails, the input keeps the text and an error message shows up.

Give every test its own account

The tests use cookie sessions. A page fixture creates a fresh user for each test and deletes that user's records afterwards. The /__test/* endpoints exist only when TEST_MODE=1 is set and skip real login, so they have no place in a deployed app. In your own project, use seeded test accounts and your real login flow.

import { test as base, expect, Page } from "@playwright/test";
import { randomUUID } from "node:crypto";

const test = base.extend({
  page: async ({ page }, use) => {
    await page.request.post("/__test/session");
    await use(page);
    await page.request.delete("/__test/session");
  },
});
Enter fullscreen mode Exit fullscreen mode

I create a new user per test because a new browser context gives you fresh cookies and storage, and that's all it gives you. Two tests logged in as the same user still write to the same rows on the server. Playwright's authentication guide makes the same point and recommends separate accounts for tests that change server state.

The shared save function starts listening for the POST response before it clicks, so a fast reply can't slip past it.

async function saveTask(page: Page, title: string) {
  await page.goto("/tasks");
  await page.getByLabel("Task name").fill(title);
  const pending = page.waitForResponse(
    (r) =>
      new URL(r.url()).pathname === "/api/tasks" &&
      r.request().method() === "POST",
  );
  await page.getByRole("button", { name: "Save", exact: true }).click();
  const response = await pending;
  await expect(page.getByRole("status")).toHaveText("Saved");
  return response;
}
Enter fullscreen mode Exit fullscreen mode

Test 1. Reload the page

test("saved task survives reload", async ({ page }) => {
  const title = `Release check ${randomUUID()}`;
  await saveTask(page, title);
  await expect(page.getByRole("list", { name: "Tasks" })).toContainText(title);
  await page.reload();
  await expect(page.getByRole("list", { name: "Tasks" })).toContainText(title);
});
Enter fullscreen mode Exit fullscreen mode

With the broken handler, the first assertion passes because the task lives in React state. After the reload the app asks the API for the list, the API returns what it stored, and the task isn't there. This is the same thing the client saw in the demo, caught by a test in a few seconds.

A passing reload test proves less than it seems. An app can rebuild its list from localStorage, IndexedDB, a service worker or an HTTP cache, and then the task survives a refresh with no database row behind it. In this demo the list always comes from the API, responses send Cache-Control: no-store, and the Playwright config blocks service workers. Even so, I want to hear from the server itself.

Test 2. Read the record back through the API

The POST response carries the new record's ID. I use it for a separate authenticated GET and compare the fields I meant to save.

test("saved task is readable through the authenticated API", async ({
  page,
}) => {
  const title = `API check ${randomUUID()}`;
  const write = await saveTask(page, title);
  expect(write.status()).toBe(201);
  const created = await write.json();
  const read = await page.request.get(`/api/tasks/${created.id}`);
  expect(read.status()).toBe(200);
  expect(await read.json()).toEqual({ id: created.id, title });
});
Enter fullscreen mode Exit fullscreen mode

page.request shares cookies with the browser context (see APIRequestContext), so this GET runs as the same user who filled in the form. If your app uses bearer tokens, set the Authorization header yourself. There's no mocked response anywhere in the persistence tests, they talk to the real local API.

The fake201 server mode shows why this test exists. It answers 201 with a believable ID and skips the insert. The status assertion passes, the follow-up GET returns 404, and the test fails.

In this app the GET reads from SQLite. In your architecture it might read a cache or a replica, so check where the read path goes before you call this a persistence test. Async APIs need a different assertion too. A 202 says the server accepted the work and nothing more, so follow the operation ID and poll for the completed state with a timeout.

An illustrative Network panel shows a task creation request returning 201 Created, followed by a GET for the same task ID returning 404 Not Found

Test 3. Request the same ID as another user

A record can be saved perfectly and still be readable by the wrong person. This test seeds a private task, checks that its owner can read it, then logs in a second user in a separate browser context and asks for that task by its ID.

A private task owned by Maya appears in Noah’s account when he requests the same task ID.

test("another user cannot read a known task ID", async ({ page, browser }) => {
  const seed = await page.request.post("/__test/seed", {
    data: { title: `Private ${randomUUID()}` },
  });
  const task = await seed.json();
  expect((await page.request.get(`/api/tasks/${task.id}`)).status()).toBe(200);
  const outsider = await browser.newContext({
    baseURL: "http://127.0.0.1:4173",
  });
  try {
    await outsider.request.post("/__test/session");
    const forbidden = await outsider.request.get(`/api/tasks/${task.id}`);
    expect(forbidden.status()).toBe(404);
    const list = await outsider.request.get("/api/tasks");
    expect(await list.json()).toEqual([]);
  } finally {
    await outsider.request.delete("/__test/session");
    await outsider.close();
  }
});
Enter fullscreen mode Exit fullscreen mode

This API answers 404 for a task the caller doesn't own. If your contract says 403, assert 403. A redirect to the login page, a 500, or a loose !response.ok() check would let a real problem pass here. The owner read at the start is a positive control, because if the task was never created, a 404 for the second user would prove nothing.

The fixed lookup filters by both the ID and the logged-in owner, and req.user comes from the server's session store, never from the request body.

const task = db
  .prepare("SELECT id, title FROM tasks WHERE id = ? AND owner = ?")
  .get(req.params.id, req.user);
Enter fullscreen mode Exit fullscreen mode

A workspace product has real roles, and a teammate may be allowed to see the record. There I'd test someone from another tenant, a read-only member, a member who was removed, and the write endpoints as well as the reads.

Test 4. Make the failed save visible

This one checks what the user sees when the save fails. It intercepts only the POST, answers with a controlled 503, and lets the GET go through to the real server.

A SaaS task form retains the user’s draft and displays an unconfirmed-save warning after a failed request

test("rejected save keeps the draft and never says Saved", async ({ page }) => {
  const title = `Rejected ${randomUUID()}`;
  await page.route("**/api/tasks", async (route) => {
    if (route.request().method() === "POST")
      await route.fulfill({
        status: 503,
        contentType: "application/json",
        body: '{"error":"Write rejected"}',
      });
    else await route.continue();
  });
  await page.goto("/tasks");
  await page.getByLabel("Task name").fill(title);
  await page.getByRole("button", { name: "Save", exact: true }).click();
  await expect(page.getByRole("alert")).toHaveText(
    "Save was not confirmed. Your draft is still here.",
  );
  await expect(page.getByRole("status")).toBeEmpty();
  await expect(page.getByLabel("Task name")).toHaveValue(title);
  await expect(page.getByRole("list", { name: "Tasks" })).not.toContainText(
    title,
  );
});
Enter fullscreen mode Exit fullscreen mode

This mock tests the frontend's error handling and tells you nothing about the database, so I keep it apart from the real-server tests.

The fixed handler checks the status before it adds the row or clears the draft.

setSaving(true);
setError("");
setStatus("");

try {
  const response = await fetch("/api/tasks", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ title }),
  });

  if (!response.ok) throw Error("Save was not confirmed.");

  const task = await response.json();
  setTasks((rows) => [...rows, task]);
  setTitle("");
  setStatus("Saved");
} catch {
  setError("Save was not confirmed. Your draft is still here.");
} finally {
  setSaving(false);
}
Enter fullscreen mode Exit fullscreen mode

A rejected save and a lost response are two different situations. The network can drop after the server has already committed the write, and then the client has no way of knowing what happened. So the message says the save wasn't confirmed, which is true in both cases. Keeping the draft is safe, and resending it blindly can create a duplicate, so before I add automatic retries to a real create flow, I give each operation a stable idempotency key and deduplicate on the server.

What the tests caught

I ran the same five tests against all four modes in Chromium, with two workers and retries turned off. The fifth test, not shown above, checks that an anonymous request can't list tasks.

Modes

Playwright HTML report with the failed reload test in broken mode

Run it yourself

The companion project has the React app, the server, the tests, the Playwright config and a lockfile. I tested it on Node 24, React 19.2.0 and Playwright 1.56.1. From the saved-demo folder on Linux or macOS, these commands run the fixed version.

npm ci
npx playwright install --with-deps chromium
npm test
Enter fullscreen mode Exit fullscreen mode

To see the bugs, run each mode on its own. These runs are supposed to exit with failures.

MODE=broken npm test
MODE=fake201 npm test
MODE=leaky npm test
Enter fullscreen mode Exit fullscreen mode

In CI, give every job a throwaway database and keep test auth state out of git. The project has a CI workflow for the fixed mode, and the numbers in the table above come from my local run.

Where I'd start in a bigger app

In a real product I wouldn't try to test every form at once. I'd pick the save flow where a lost record costs the most and add one real-server create-and-read test, one access test with a specific expected status, and one controlled failure test.

If an AI agent built the feature, you can hand it this prompt and then review the tests it writes. Replace the parts in square brackets with your own names.

Write Playwright tests for the [create task] flow in this app.

1. Create a [task] through the UI, reload the page, and assert it is still in the [Tasks] list.
2. Take the ID from the POST response, GET [/api/tasks/:id] with the same session, and assert status 200 and the saved fields.
3. Log in a second user in a new browser context, request the same ID, and assert [404].
4. Make the POST return 503 with page.route, then assert that "Saved" never appears, the draft stays in the input, and an error is shown.

Give every test its own user account. Do not mock the API in tests 1 to 3.
Enter fullscreen mode Exit fullscreen mode

Four green tests don't make an app production-ready. They do show whether one specific Saved message holds up after a reload, an API read, a second user and a failed request. Before your next demo, save one record and read it back as the person who will need it tomorrow.

What's the strangest fake success you've seen in an AI-built app? Tell me in the comments.

Frequently asked questions

Why does a task disappear after refreshing an AI-built app?

The frontend may have updated local state even though the write failed, or the reload may query a different account or data source. Look at the POST response and the GET that follows it. A disappearing record on its own doesn't tell you which cause you have.

How do I test database persistence with Playwright?

Create the record through the UI, then read it back by ID through an authenticated API request and compare the stored fields. Confirm that the endpoint reads the database you care about, since a refresh test can pass on browser-stored data.

How do I test data isolation between SaaS accounts?

Create a record for its owner and confirm the owner can read it. Then log in a second user in a separate browser context, request the same ID, and assert the documented denial status. Extend the test to write endpoints and to the tenant roles your product has.

Can I mock API calls in a persistence test?

Mock a failed response when you test how the UI reacts to failure. Use the real write and read endpoints when you check saved state, because a mocked create response passes even when the backend is completely broken.

Thanks everybody!

I'm Lead Full Stack Developer at UITOP. This check is one small piece of taking a vibe-coded prototype to production 🤝

Top comments (1)

Collapse
 
posting-dude profile image
Posting Dude •

The server that answered 201 and wrote nothing passing the failed-save test is the scary one, because the UI did everything "right" there. Only the read-back catches it. Do you run the different-user check against list and search endpoints too, or just the single record GET? Leaks through a list filter seem a lot easier to miss than on /tasks/:id.