Create the object store gracefully when it doesn’t exist#138
Create the object store gracefully when it doesn’t exist#138iamakulov wants to merge 1 commit intojakearchibald:mainfrom
Conversation
|
Last time I tried something like this, I ran into deadlock issues in IE11, so I'll need to do a lot of testing there. |
|
FWIW here’s the code I used to reproduce the issue and test the fix: <!-- dist/index.html -->
<!doctype html>
<script src="./umd.js"></script>// In the console:
// ...Create the DB
await idbKeyval.set('a', 'b')
await idbKeyval.get('a') // → Must return b
window.location.reload() // Reload to close all connections to the DB
// ...Destroy the DB and create the DB without the store
indexedDB.deleteDatabase('keyval-store')
indexedDB.open('keyval-store')
window.location.reload() // Reload to close all connections to the DB
// ...Ensure the missing store is added
await idbKeyval.set('a', 'b')
await idbKeyval.get('a') // → Must return b
const dbOpenRequest = indexedDB.open('keyval-store')
dbOpenRequest.onsuccess = function(event) {
console.log(db.version); // → Must return 2
}; |
|
How does this happen in the real world? Is it when someone manually creates the database of that name but doesn't create the store, or are you seeing cases where the store disappears? |
That was the case for me. I can’t really reproduce it; it’s just that I wrote the code that used |
|
"opened Safari a few days later" sounds as if this is somewhat related to the "ephemeral" nature of IDB in Safari… |
|
Right, but it shouldn't be removing individual stores. |
|
Actually, the PR might accidentally introduces a new feature: create multiple key-value instance (in different object store) under one database. |
Fixes #134.
This PR ensures
idb-keyvalcreates the object store when the DB exists but the object store doesn’t.I stumbled upon the same issue @getflourish experienced (#134), and also in Safari. This PR seems to fix the issue nicely.
Tested in Chrome, Safari, and Firefox.