Clarify that deleteDatabase() blocks until open connections close - #44350
Clarify that deleteDatabase() blocks until open connections close#44350vamshikrishnaramasamy wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Preview URLs (1 page) (comment last updated: 2026-06-22 20:58:54) |
chrisdavidmills
left a comment
There was a problem hiding this comment.
@vamshikrishnaramasamy some comments for you.
|
|
||
| When `deleteDatabase()` is called, any other open connections to this | ||
| particular database will get a [versionchange](/en-US/docs/Web/API/IDBDatabase/versionchange_event) event. | ||
| The deletion does not complete while other connections to the database are still open. |
There was a problem hiding this comment.
I would delete this sentence, as it is placed strangely and repeats what is said in the note.
There was a problem hiding this comment.
Removed it — agreed it was redundant with the note.
| giving them the opportunity to close so that the deletion can proceed. | ||
|
|
||
| > [!NOTE] | ||
| > If a connection is not closed in response to the `versionchange` event, the deletion is |
There was a problem hiding this comment.
Take this all out of the note block — it works better as regular text, as all of this addition is part of a single flow.
There was a problem hiding this comment.
Pulled it out of the note block; it flows better as plain prose now.
| > blocked: the request's `success` event does not fire, and a | ||
| > [`blocked`](/en-US/docs/Web/API/IDBOpenDBRequest/blocked_event) event is fired on the | ||
| > request instead. The deletion stays pending until every connection to the database is | ||
| > closed. To let it complete, close each connection — for example by calling |
There was a problem hiding this comment.
I would put "To let it complete..." as a separate paragraph. I'd also edit it to something like
To let it complete, close each connection. This is typically done by calling {{domxref("IDBDatabase.close()")}} from inside the
versionchangeevent handler.
This works better, as you already mentioned versionchange previously.
Maybe also add a short code snippet to show what that typically looks like, and/or link to an example?
There was a problem hiding this comment.
Reworded to your version and split it into its own paragraph. I also added a small snippet showing the versionchange handler closing the connection, matching the style on the versionchange_event page.
chrisdavidmills
left a comment
There was a problem hiding this comment.
@vamshikrishnaramasamy thanks! Just one more comment for you.
|
|
||
| ```js | ||
| // db is an open connection (e.g. from a previous indexedDB.open() success) | ||
| db.onversionchange = () => { |
There was a problem hiding this comment.
My only remaining comment is that I would rewrite this using addEventListener(). That's the more modern practice, and what we usually do in MDN examples.
There was a problem hiding this comment.
Updated the snippet to use addEventListener("versionchange", ...) instead. Thanks for the pointer.
Fixes #20368.
The page mentions that open connections receive a
versionchangeevent, but doesn't explain the consequence: the deletion will not complete (andsuccesswill not fire) while any connection to the database is still open. This is a common source of confusion — people wait foronsuccessthat never comes because a connection is left open.This expands the existing sentence to spell out that:
blockedevent is fired on the request if a connection doesn't close in response toversionchange;IDBDatabase.close()) lets the deletion proceed.This matches the spec's database-deletion steps and the behavior @evanstade quoted on the issue.