0

We are using the Facebook IndexedDB Polyfill to allow the IndexedDB API to be utilised in Safari/ Mobile Safari. However, we are experiencing a "TransactionInactiveError" when attempting to update records - the error originates from line 1567 of the Polyfill.js file: if (!me._active) throw new util.error("TransactionInactiveError");

Here's a quick example I've put together. Simply add the Facebook Polyfill script tag reference and run in Safari:

var db;
var request = indexedDB.open("polyfillTest");

request.onupgradeneeded = function () {
    // The database did not previously exist, so create object stores and indexes.
    db = request.result;
    var store = db.createObjectStore("books", {keyPath: "isbn"});
    var titleIndex = store.createIndex("by_title", "title", {unique: true});
    var authorIndex = store.createIndex("by_author", "author");

    // Populate with initial data.
    store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
    store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
    store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});

    updateItem(store);
};

request.onsuccess = function () {
    db = request.result;
};

function updateItem(store) {
    var request = store.get(123456);

    request.onsuccess = function () {
        var book = request.result;
        book.title = "New Title";
        book.author = "New Author";

        var updateRequest = store.put(book);
        updateRequest.onsuccess = function (evt) {
            console.log("Book updated successfully.");
        };
        updateRequest.onerror = function (evt) {
            console.error("Book could not be updated.");
        };
    };
}

Any help appreciated!

Many thanks

Liam
  • 1
  • 1

1 Answers1

1

Transactions are typically kept active until the last callback with a reference releases that reference. So this suggests to me your transaction is auto-commiting.

I suspect it may have something to do with your re-use of the versionchange transaction for puts and gets. After many headaches with this issue, in my library I've opted for a model where I allow all version change transactions to fully commit before trying to do CRUD operations on the same store.

I'm not fully able to explain why, but based on many days of frustration, keeping long-lived versionchanges seems to be a bad idea.

Community
  • 1
  • 1
buley
  • 28,032
  • 17
  • 85
  • 106