theatre-js / theatre

Motion design editor for the web
https://www.theatrejs.com
Apache License 2.0
10.86k stars 338 forks source link

Add method to clear persistent storage #142

Closed donmccurdy closed 1 year ago

donmccurdy commented 2 years ago

Possible solution to an issue we discussed briefly in Discord — our application registers an extension, and displays a button allowing users to save their changes to a file. We enable persistent storage in case the page crashes or reloads before changes have been saved. In some cases the user may decide not to save the changes they've made since the last save, in which case we need a way to clear persistent storage.

I've tried just clearing all localstorage entries with the right prefix and then reloading, but then theatre.js is doing one last commit to localstorage before the page reloads and the cache persists. This PR would expose a new method, studio.clearPersistentStorage(), which could be used by userland code or extensions.

This contribution is funded by The New York Times.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
theatre-playground ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 8, 2023 at 11:04AM (UTC)
vezwork commented 1 year ago

Thanks for the PR @donmccurdy, also thanks for the clear comments and code.

Update: we are discussing this area of the API internally. We want to keep this PR open during that process. I can't currently give you a timeline, but will keep you updated as we make progress.

donmccurdy commented 1 year ago

@vezwork just following up here — we're still looking for some way to clear the cache. Would welcome even an "experimental" API for that purpose!

AriaMinaei commented 1 year ago

Thanks @donmccurdy! Just note that I've renamed the API to: studio.__experimental.__experimental_clearPersistentStorage(persistenceKey)

craigthings commented 10 months ago

I wonder if an alternative to this would be to add a config param when initializing studio to disable persistent storage? There are some cases I can imagine where storing and restoring state would be managed in userland.