Ask the browser to keep saved work, and warn when it may clear it - #438
Merged
Merged
Conversation
Without a local server, flows and responses live in localStorage and files in IndexedDB, which browsers may clear to free up space. Safari also deletes a site's script-written data after 7 days of use without visiting it. Request persistent storage (navigator.storage.persist()) the first time work is saved in a session: a manual Save, or a file uploaded or generated into the browser. Never on page load, since Firefox prompts. When storage isn't protected (declined, unsupported, or Safari outside a Home Screen or Dock web app), show a dismissible notice with an Export button, and say so in the Save button's tooltip. Local installs are unaffected; they save to disk. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Asks the browser not to clear ChainForge's saved work when it runs without a local server, and tells people when their work isn't protected, so they can export it.
Why
Without a local server, ChainForge keeps everything in the browser:
localStorage.Browsers treat both as "best effort" by default:
Nothing requested persistent storage or warned about this, so browser-only users could lose flows and images without notice. Local installs (
chainforge serve, the Mac app) aren't affected: flows and files are saved to disk.What changed
Requesting persistence:
navigator.storage.persist()is called the first time someone saves work in a session:It's never called on page load, since Firefox asks the user; the prompt should follow something they did. It's requested at most once per session, and checking the current state never prompts.
Notice: if storage isn't protected, a dismissible notice appears below the toolbar with an Export flow button. It explains why:
Safari counts as at risk even when it grants persistence, since Apple documents no exemption from the 7-day deletion except for Home Screen and Dock web apps. Those count as protected when granted.
Dismissing: remembered in that browser. If the browser clears storage, the notice returns, when it's needed again.
Save tooltip: says whether the browser agreed to keep the flow, or repeats the warning.
Code:
backend/storagePersistence.ts(new) holds the state, requests, and dismissal.MediaLookup.uploadToBrowserrequests persistence.App.tsxrequests on manual Save and shows the tooltip status and notice.How browsers decide
persist()Sources: MDN: Storage quotas and eviction criteria, web.dev: Persistent storage, WebKit: Updates to Storage Policy, WebKit: Full Third-Party Cookie Blocking and More
Limits
Testing
storagePersistence.test.ts, 13 tests:persist(), and doesn't override a request;tscis clean, ESLint has no errors, and the build compiles.🤖 Generated with Claude Code