Closed rdcw closed 3 years ago
When using idb.js in a worker context on Safari, you get
TransactionInactiveError: Failed to execute 'get' on 'IDBObjectStore': The transaction is inactive or finished.
However, when running the same code in the main context, or on chrome or firefox in the main or in a worker context, it works as expected.
const DB_NAME = "db-123"; const STORE_NAME = "store-name"; const dbPromise = idb.open(DB_NAME, 1, upgradeDB => { upgradeDB.createObjectStore(STORE_NAME); }); const init = async () => { const db = await dbPromise; const txWrite = db.transaction(STORE_NAME, "readwrite"); await txWrite.objectStore(STORE_NAME).put("hello", "foo"); const txRead = db.transaction(STORE_NAME); console.log(type, "got transaction"); const a = await txRead.objectStore(STORE_NAME).get("foo"); console.log(type, "got a", a); const b = await txRead.objectStore(STORE_NAME).get("foo"); console.log(type, "got b", b); }; init().catch(e => console.error(e));
In Safari, this code will output
[Log] MAIN – "got transaction" [Log] MAIN – "got a" – "hello" [Log] MAIN – "got b" – "hello" [Log] WORKER – "got transaction" [Log] WORKER – "got a" – "hello" TransactionInactiveError: Failed to execute 'get' on 'IDBObjectStore': The transaction is inactive or finished.
Whereas in Chrome or Firefox you don't get the TransactionInactiveError.
TransactionInactiveError
There is a sandbox here https://codesandbox.io/s/rj4wnn5lzn
Sorry I never got to this, but it seems like Safari has fixed the issue.
When using idb.js in a worker context on Safari, you get
TransactionInactiveError: Failed to execute 'get' on 'IDBObjectStore': The transaction is inactive or finished.
However, when running the same code in the main context, or on chrome or firefox in the main or in a worker context, it works as expected.
In Safari, this code will output
Whereas in Chrome or Firefox you don't get the
TransactionInactiveError
.There is a sandbox here https://codesandbox.io/s/rj4wnn5lzn