moutard / SubZoom-Proto1

1 stars 1 forks source link

Uncaught Error: InvalidStateError: DOM IDBDatabase Exception 11 #38

Closed moutard closed 12 years ago

moutard commented 12 years ago

https://groups.google.com/a/chromium.org/forum/?fromgroups#!topic/chromium-html5/VlWI87JFKMk

TL;DR: You can no longer call db.transaction() or db.setVersion() from inside a setVersion transaction. Its fairly rare for code to do this, but you may want to read on just in case.

This is an update to the earlier message about "Error/exception behavior changing" - The work there has uncovered a possibly more visible issue with our current implementation. I still suspect that nobody will be affected by this but I wanted to give a heads up just in case.

You can make these changes to your code today without waiting for the changes to land in Chrome.

Landing later this week in Chrome canary: you can no longer create any kind of transaction from inside a versionchange transaction, as a result of calling setVersion(). This will also apply when we (chrome) finishes transitioning to the spec-compliant onupgradeneeded system: you won't be allowed to create a new transaction from inside the versionchange transaction. Instead, you should create the transaction in the oncomplete handler for the versionchange transaction.

For example, if you had code that looked like this:

db.setVersion('3').onsuccess = function(version) { ... db.transaction('mystore', 'readwrite').onsuccess = populateDataStore; }

This needs to be changed slightly to call populateDataStore after the end of the transaction:

db.setVersion('3').onsuccess = function(event) { var transaction = event.result; transaction.oncomplete = function() { db.transaction('mystore', 'readwrite').onsuccess = populateDataStore; }; }

The same is true if your code previously chained together setVersion calls:

db.setVersion('3').onsuccess = function(version) { ... db.setVersion('4').onsuccess = updateToVersion4; }

This needs to be changed slightly to call populateDataStore after the end of the transaction:

db.setVersion('3').onsuccess = function(event) { var transaction = event.result; transaction.oncomplete = function() { db.setVersion('4').onsuccess = updateToVersion4; }; }

Please update to this pattern as soon as you can, so that nobody breaks when this lands.

Let me know if you have any questions,

Alec