mdn/content

indexedDB.deleteDatabase doc: Mention that deleting a database isn't completed until the upgradeNeeded result is closed

Open

#20.368 aperta il 7 set 2022

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Markdown (22.427 fork)batch import
Content:WebAPIaccepting PRarea: IndexedDBhelp wanted

Metriche repository

Star
 (8900 star)
Metriche merge PR
 (Merge medio 7g 3h) (147 PR mergiate in 30 g)

Descrizione

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/deleteDatabase

What specific section or headline is this issue about?

No response

What information was incorrect, unhelpful, or incomplete?

When calling IDBFactory.deleteDatabase(), the database isn't deleted until the upgradeneeded event is garbage collected, which can by triggered by calling request.result.close() on the indexedDB.open() result.

What did you expect to see?

Mention that onsuccess won't be fired until the indexedDB.open() result is closed like so:

const request = indexedDB.open(dbName);
request.onupgradeneeded = () => {
  request.result.close();
}

though to be honest I'm not sure how much of this depends on my specific situation. I reckon there might be other calls that similarly cause a database to stay open like this.

Do you have any supporting links, references, or citations?

Initially I thought this was a bug in Chrome, so I reported https://bugs.chromium.org/p/chromium/issues/detail?id=1359843. But it seems like this behaviour is intentional. You can find an example of this behaviour at https://indexeddb-deletedatabase-hanging.glitch.me/ you'll see that unless you have the 'close indexedDB.open() result' checkbox checked, deleting databases will take significantly longer depending on how fast the objects are garbage collected.

Do you have anything more you want to share?

No response

MDN metadata

Guida contributor