All posts

Saving in one tab wipes another tab's changes? Lost updates

A user says: "I changed the price, and an hour later it was back to the old one." Nobody gets an error. The data is simply gone, because a second save, from another tab or another person, wrote an older copy over it. This is called a lost update. I found this bug in my own app 3P on November 12, 2026: with two tabs open, saving a decision in one tab deleted the decisions saved in the other. It was fixed the same day, and section 1 shows how. Vendor facts below come from each vendor's own docs, checked in November 2026.

Short answer: A lost update happens when your app loads a copy, the user edits it for a while, and the save sends the whole copy back. Fix it in two layers. First, save only what changed: single fields, not the whole record, and never a whole list. Second, add a version check, so a save based on an old copy is refused instead of applied. Then tell the user what happened, and keep their typing so they can redo it.

1. How the lost update happens

The pattern is simple, and it is everywhere:

  1. Tab A loads a product: name "Lamp", price 40, stock 12.
  2. Tab B loads the same product.
  3. In tab A, someone sets the price to 35 and saves. The database now holds price 35.
  4. In tab B, someone fixes a typo in the name and saves. Tab B sends its whole copy, including price 40.
  5. The price is 40 again. Nobody saw a warning.

Tab B could be the same person in a second tab, a colleague, a phone that was left open since this morning, or an automatic save that fires later. The cause is the same: the save writes values the user never touched.

Your database cannot see this. The gap between loading and saving can be minutes, and no database transaction stays open that long. PostgreSQL's isolation docs describe conflict errors such as "could not serialize access due to concurrent update", but those apply to transactions that overlap inside the database. Two separate requests, sent minutes apart, are two separate transactions, and the second one simply wins. You have to build the check into the app.

The worst version: saving a whole list

3P stored a person's decision history as one list. Each tab kept its own copy of that list in memory. When a tab saved a new decision, it wrote its whole list back. A decision saved in the other tab a minute earlier was not in that copy, so it disappeared. Any app that keeps a list inside one record has this risk: a JSON column with all of a user's items, a Firestore document with an array, or a list in localStorage. The fix in 3P was to read the saved list again right before each change, and to apply only that one change to it.

2. Layer one: save only what changed

Most lost updates disappear if a save sends only the fields the user edited. If tab B sends only the new name, the price from tab A survives.

  • SQL apps (Supabase, Neon, any Postgres): update the changed columns, not the whole row. For counters and stock, let the database do the math: update products set stock = stock - 1 where id = 42, never "read 12, write 11" from the browser.
  • Firestore: the add data guide says that with set() on an existing document, "its contents will be overwritten with the newly provided data, unless you specify that the data should be merged into the existing document". Use updateDoc with only the changed fields, or set with merge.
  • Lists in Firestore: the same guide says "you can use arrayUnion() and arrayRemove() to add and remove elements. arrayUnion() adds elements to an array but only elements not already present." Use those instead of writing the whole array.
  • Lists in a JSON column: better, give items their own table, one row per item. Then adding an item is an insert, and it can never remove another item.

3. Layer two: refuse a save based on an old copy

Saving only changed fields still loses work when two people edit the same field. For that, add a version number. This is often called optimistic locking.

  1. Add a column version integer not null default 1.
  2. When the app loads a record, it keeps the version it saw.
  3. The save only updates the row if the version is still the same, and raises it by one.
  4. If no row was updated, someone else saved first. Show a conflict instead of overwriting.
update products
set price = 35, version = version + 1
where id = 42 and version = 7
returning id, version;
-- 1 row back: saved. 0 rows back: someone saved first.

The PostgreSQL UPDATE docs say "The optional RETURNING clause causes UPDATE to compute and return value(s) based on each row actually updated." So zero returned rows means the version did not match.

With the Supabase JavaScript client, note the default from the update reference: "By default, updated rows are not returned. To return it, chain the call with .select() after filters." Without .select() you cannot tell a save from a silent miss.

const { data, error } = await supabase
  .from('products')
  .update({ price: 35, version: loadedVersion + 1 })
  .eq('id', 42)
  .eq('version', loadedVersion)
  .select()
if (error) throw error
if (data.length === 0) showConflict() // someone saved first

Row Level Security can also make an update match zero rows, so test the conflict path with a user who is allowed to edit. Also make sure the version comes from the database, never from a field the user can type in.

If your app has its own API

HTTP has this check built in. MDN's If-Match page says that "in particular for PUT, If-Match can be used to prevent the lost update problem. It can check if the modification of a resource that the user wants to upload will not override another change that has been done since the original resource was fetched." The ETag page explains the flow: the server sends an ETag with the data, the save sends it back in If-Match, and "If the hashes don't match, it means that the document has been edited in-between and a 412 Precondition Failed error is thrown." Your version number can serve as the ETag.

Firestore: transactions

Firestore's transactions page says that if a transaction reads documents "and another client modifies any of those documents, Cloud Firestore retries the transaction." That protects a read-then-write done in one go, such as a counter. It does not cover the minutes a user spends in a form, so store a version field and check it inside the transaction before you write. Also note: "Transactions will fail when the client is offline."

4. What the user should see on a conflict

Never drop the user's work. A good conflict message:

  • Says what happened in plain words: "This product was changed in another tab or by someone else since you opened it."
  • Keeps what they typed on screen, so they can copy it.
  • Offers one clear action: "Load the latest version", then they redo their change.

For simple records you can merge automatically: if the other save changed the price and this one changed the name, apply only the name and save again. If both changed the same field, ask the user. For apps where several people edit together all day, show live changes instead, see realtime or polling.

5. The same user in two tabs

Data that lives in the browser has the same problem, and the fix is the one 3P got: read the stored copy again right before each change, then write. The browser can also tell other tabs that something changed:

  • MDN's storage event page: the event "fires when another document that shares the same storage area (either localStorage or sessionStorage) as the current window updates that storage area. The event is not fired on the window that made the change." Listen to it and reload your in-memory copy.
  • MDN's BroadcastChannel page: it "allows communication between different documents (in different windows, tabs, frames or iframes) of the same origin." Post a short "saved" message after each save, so other tabs refresh.

These messages keep tabs in sync. The version check in your database is still what stops the overwrite, because a message can arrive late, or a tab can be asleep.

Prompts for Lovable, Bolt and Cursor

  • "Find every save in this app that sends a whole record or a whole list back to the database. Change each one to send only the fields the user changed, and change counters to update in the database (stock = stock - 1). List every place you changed."
  • "Add an integer version column to the products table. Load it with each product. On save, update only where id and version match, raise the version by one, and use .select() to check that a row came back. If no row came back, keep the form as it is and show: 'This was changed by someone else. Load the latest version.'"
  • "This app keeps data in localStorage. Before every change, read the stored data again and apply only that change. Listen to the storage event so other open tabs reload their copy."

Checklist

  1. Saves send only changed fields, not whole records.
  2. No save writes a whole list. Items have their own rows, or you use arrayUnion and arrayRemove.
  3. Counters and stock change inside the database.
  4. Records people edit have a version column, and saves check it.
  5. A failed version check shows a clear message and keeps the user's input.
  6. Browser-stored data is read again right before each change.
  7. You tested it: two tabs, edit both, save both, and see what survives.

The two-tab test belongs in your test list, see first tests for an AI-built app. Double saves from one click are a different bug with a different fix: duplicate records from double clicks and retries. And if data is already lost, read how to undo deleted data.

Want this fixed for you?

I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including saves that silently overwrite other people's changes. Or send me the details and I'll reply within 24 hours.