GuidesUpdated

Why does my AI-built app lose data when I refresh?

Find out whether Save writes to UI state, browser storage or a real backend, then test the kind of persistence your product promises.

On this page

A form can show a success message and still forget everything after a reload. Before asking an agent to 'fix saving', decide where the data should live. A single-user practice board can use browser storage; a shared customer app usually needs an authorized backend and database. That decision, not the button, sets the fix.

Canopy project workspace for running and reviewing an AI-built app
Canopy project workspace for running and reviewing an AI-built app

Reproduce the exact loss before editing

Use a disposable record. Note the URL, account and browser, then save and reload once. Does the value vanish immediately, after a full refresh, after closing the tab, or only on another device? Each is a different failure.

In Canopy, run the app from the intended checkout; another server or branch can hide a fix.

  • Write down the expected scope: this tab, this browser, this account, or every signed-in device.
  • Don't clear storage or reset the database during diagnosis.

Find where Save writes

Inspect the Save handler and the Network panel. If no write request fires, the page may only change component state or browser storage. React describes state as UI memory tied to the rendered tree, not a database. MDN says localStorage survives browser sessions for its origin; sessionStorage ends with the page session. Chrome's Application panel shows both.

A successful request isn't enough either: check its status and the backend record in the test environment.

What a reload test can reveal. Check the code and request before deciding.
Observed behaviorPlace to inspectWhat it does not prove
Value disappears on refreshComponent state, Save handler, request logThat the database is broken; there may be no write
Survives refresh in one browserLocal Storage, IndexedDB or backend readThat another user or device can see it
Survives browser close on one deviceOrigin-scoped browser storage or backendThat it is backed up or account-owned
Appears on another signed-in deviceBackend record, auth rule, fresh readThat every user has correct access

Choose the persistence the feature needs

In the included first-agent practice board, localStorage is intended: the README says tasks stay in this browser, with no login or backend. Customer profiles or team records need an owner, access rules, error handling and a backend.

Don't swap a broken backend write for localStorage to pass the refresh test; that hides sync and access problems. If you need a backend, confirm its development target first so the agent doesn't test against production.

  • Write the expected persistence scope into the task brief.
  • Get qualified review for account, authorization, migration or customer-data changes.

Ask the agent for a fix you can check

Give the agent the reproduction and ask it to trace the Save handler, storage or API call, reload path and tests before editing. Acceptance covers a successful save, a failed save, a refresh, and a second context: a new tab for browser storage, or another signed-in device for account data.

Then repeat the sequence yourself in Canopy Preview and compare the diff with the agreed storage rule.

  • Show success only after a confirmed save, not on click.
  • A failed write keeps the input and explains what happened.

Check the PR for demo-only shortcuts

Read the diff for hardcoded sample values, a Save that only changes UI state, a storage fallback that hides backend errors, or a test reduced to checking a toast. Schema, API or auth changes need their own review.

A passing build and a screenshot can't show what happens after refresh or for another user. Accept the task when behavior matches the written persistence promise.

Copyable resources

Data disappears after refresh: agent task

Replace the storage promise with what this product needs.

Page, URL, browser, account, checkout and branch: [ ]
Disposable test record: [ ]
Steps: create or edit [ ]; click Save; observe [ ]; refresh; observe [ ].
Expected persistence: same tab / same browser / same account across devices [choose one].
Before editing: trace the Save handler, browser storage, network write, backend target, reload read and existing tests. Cite files and unknowns.
Test environment and data: [ ]; no production data.
Acceptance: successful save; failed save keeps input; refresh; second tab or second device/account as appropriate.
Delivery: running URL, request or storage evidence, tests and results, changed files, final diff, remaining risks.

Frequently asked questions

Is localStorage the same as a database for my users?

No. It's browser storage scoped to one origin and browser. It suits a local single-user exercise, but it doesn't sync an account across devices or act as a shared backend.

Why did the success message appear if nothing saved?

The UI may show success after a local state change or before checking the server's response. Trace the handler and request, then check the value after a fresh read or reload.

Does a page surviving refresh prove the feature is ready?

No. Check the promised persistence scope, failure behavior, access rules and diff. Browser storage survives refresh without making the record available to the right account elsewhere.

More questions and answers →

Sources and further reading