Invental/Review lessons/Client state that goes stale

Client state that goes stale

Never roll back a change the server accepted

Put only the server call inside the rollback block; once the server has accepted a mutation, a failed refresh is a logging problem, not a reason to undo the user's change.

01 · Before and afterThe pattern

TypeScript
// before: refresh failure rolls back a committed change
try { const r = await api.move(id, to); tx.commit(r); await refresh(); }
catch (e) { tx.rollback(); throw e; }

// after: rollback only covers the mutation itself
try { const r = await api.move(id, to); tx.commit(r); }
catch (e) { tx.rollback(); throw e; }
refresh().catch((e) => log("refresh after move failed", e));

02 · Run it on your appThe check

If the refresh after a successful save fails, does your UI undo the save or show it as an error?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.