Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari Worker issue #73

Closed
rdcw opened this issue Dec 3, 2018 · 1 comment
Closed

Safari Worker issue #73

rdcw opened this issue Dec 3, 2018 · 1 comment

Comments

@rdcw
Copy link

rdcw commented Dec 3, 2018

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.

There is a sandbox here https://codesandbox.io/s/rj4wnn5lzn

@jakearchibald
Copy link
Owner

Sorry I never got to this, but it seems like Safari has fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants