jakearchibald / idb-keyval

A super-simple-small promise-based keyval store implemented with IndexedDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

EdmundsEcho opened this issue · comments

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?

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

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.

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.