jakearchibald / idb-keyval

A super-simple-small promise-based keyval store implemented with IndexedDB
Other
2.76k stars 147 forks source link

how to "re-establish" a key-value index that was deleted by the user #159

Open EdmundsEcho opened 2 years ago

EdmundsEcho commented 2 years ago

I use idb-keyval to track user-driven changes in the ui-state (e.g., whether to show a detailed view of a component). The ability to write to a db does not depend on the initial presence of a db (the api just creates a new instance)... except when the user has deleted the key-val index in the dev-console/Storage tab.

The only solution/hack I have found thus far is to change the name of the db. This seems to be because a db can only have one "table"/index. So, deleting an index effectively requires a new db.

To be more specific with the issue, the starting state in "Storage" is db-ui-state/tbl-stateid-value where the idbStore was initialized as follows:

// DB = db-ui-state, TBL = tbl-stateid-value
const idbStore = createStore(DB, TBL);

If I delete tbl-stateid-value, the app subsequently generates errors when I would expect that it "re-establish" the instance.

Has anyone encountered this situation? How might I re-establish the ability to write to the deleted index?

scamden commented 1 year ago

@EdmundsEcho how are you able to delete that? in my chrome devtools panel i can only "clear" the table or delete the whole DB

EdmundsEcho commented 1 year ago

It happened in Firefox. I'm not sure I tried to replicate in chrome and others. I'll see if I can compare the "delete" options. Maybe Firefox enables a more "severe" delete.

Ulisseus commented 8 months ago

It's a very unlikely case but in Firefox user can manually drop the store which can cause all sorts of problems. Unfortunately, even closing the tab or restarting the browser does not fix it.

@EdmundsEcho how are you able to delete that? in my chrome devtools panel i can only "clear" the table or delete the whole DB

Something like this. There is a DB 'coh_external_cache' with store 'responses'

image

Afterwards the DB is still there (or maybe recreated) but the store is missing, so every set request to this store fails. It would be nice if the missing store was recreated on such errors. But again it's a such bizarre scenario (user manually doing something trough dev tools in certain browser), so I just wrote it off.