Save data in the browser, safely
Safe local-storage layer
For when the answer to “It remembers things after a refresh” is yes.
Kills the 'localStorage is not a database' footgun: versioned schema with forward-only migrations, quota and parse-corruption handling that reports instead of losing data silently, and an export/import backup path.
Built by hand again in 14 of 20 audited projects before this existed. Each rebuild was another chance to make the mistake below.
Skip the rebuild
You do not write this one. It arrives in your project as ordinary source you can read, change and keep, with its audit record and its caveats beside it.
- Download the Playground. It is free and runs on your own machine.
- Start a new app and tick “It remembers things after a refresh”.
- This block is written in, along with anything else you ticked.
The mistake it removes
Rebuilt in ~14/20 projects and repeatedly flagged in audits. The Coaching App FAILED its audit on exactly this: no export, silent failure modes.
What the audit found
Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.
- load() pre-probes storage with a write, so a full quota returns DEFAULTS over readable saved data major · Correctness / Data durability Fixed after the audit in
492e3747a - useStore rebuilds the store and writes localStorage on EVERY render when onError is an inline function major · Correctness (React stack) Fixed after the audit in
b673e8459 - Two mutants survived the suite: save() dropping the schemaVersion stamp, and legacy-key precedence reversed major · Verification integrity Fixed after the audit in
c3cd5f4b2 - The corrupt-data message asserts 'A copy was kept' even when keeping the copy failed minor · Error handling & resilience Fixed after the audit in
7edcaec82 - A stored JSON array passes the object check and is spread into numbered keys minor · Correctness Fixed after the audit in
8b1a2188a - A save written by a NEWER app version is silently stamped down to the current version minor · Correctness Fixed after the audit in
5708ed38e - Corrupt copies accumulate without pruning (open since the 2026-07-17 record) minor · Stress & robustness Fixed after the audit in
b9c00b936
One more finding is written in the auditors' internal shorthand, so it is not listed here. The full text is in the report inside the block. It was fixed after the audit, in 61c5e9828.
What you still have to do
A copied file cannot own your secrets, your host or your legal obligations. This is the part the block deliberately does not claim.
- A backup your user can actually restore from: a server-side copy, or a prompt that makes them use the export path on a schedule. localStorage is cleared with site data and by storage pressure; versioned migrations keep a save READABLE, they do not keep it alive.
What lands in your project
vanilla
- vanilla/store.js
Plain ES module. No build step, no dependencies.
react
- react/useStore.js
- vanilla/store.js
The hook plus the vanilla core it wraps: both land side by side so `./store.js` resolves.
What you supply
- key: app:save
- version: 1
Licensed MIT. It is a starting point, not a finished product.
Get it
Download the Playground See the other blocks
Nothing here is locked. The files are yours, in your folder, under a permissive license.
Questions
- Is Save data in the browser, safely audited?
- It was audited on 2026-09-29, and the verdict was not a clean pass. 8 findings have been fixed since then, and the verdict stands until the block is audited again.
- What do I still have to do myself?
- A backup your user can actually restore from: a server-side copy, or a prompt that makes them use the export path on a schedule. localStorage is cleared with site data and by storage pressure; versioned migrations keep a save READABLE, they do not keep it alive.
- How do I get this code?
- Download the Playground, start a new app, and tick “It remembers things after a refresh”. The block is written into your project as ordinary source you can read and edit.
All pre-built code blocks · Learn to build from zero · The coding guide