dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.69k stars 641 forks source link

Failed to execute 'objectStore' on 'IDBTransaction': The transaction has finished #1564

Open jawalkwan opened 2 years ago

jawalkwan commented 2 years ago

code: 11 message: "Failed to execute 'objectStore' on 'IDBTransaction': The transaction has finished." name: "InvalidStateError"

my code is simple: return await this.table.update(id, { examineDate: data.examineDate }) but,it return error notice like that ↑,I found so many answers from google and github and stackoverflow but no one useful help me please,it's very urgent, thx @dfahlander 🙏

dfahlander commented 2 years ago

This happens when you execute a transaction and await non-Dexie calls within it.

await db.transaction('rw', db.myTable, async () => {
  await fetch('https://xyz.org/...'); // Here's a problem: awaiting non-dexie call within a transaction
  return await this.table.update(id, { examineDate: data.examineDate });
});

This is also described here

If your function is not executing within a transaction, the case can also be that your caller has the transaction block and calls your function within it after doing the non-dexie work.

Let me know if that was the case and what version of dexie you are using.

jawalkwan commented 2 years ago

alright, I installed latest version dexie in my project my code in function just has one line ,like this:

async update(data: any) {
return await this.table.update(id, { examineDate: data.examineDate })
}

haven't transaction around of them. I ever tried to write the transaction around of this codes, but didn't work

dfahlander commented 2 years ago

Are you using a very old browser or Internet Explorer, Legacy Edge or very old version of some other browser?

dfahlander commented 2 years ago

These type of problems occur on very old browsers - but also when using IndexedDBShim or possibly also fakeIndexedDB instead of using the native IndexedDB in the browser.

One workaround is to transpile the application code to <= ES2016 to get rid of the ES2017 async/await keywords which in those environments are incompatible with IndexedDB transactions.

jawalkwan commented 2 years ago

I using the latest version electron, it included chromium version about 100.x, so I don't think about it's reason for browser's version. My frontend platform using vue3+vite,it would translate the typescript code to es2015 and support async/await better, I also not doubt the trouble is from code's version maybe i was wrong, if you need, I can make and share a demo with the problem to you for position the problem

jawalkwan commented 2 years ago

btw, did you have obstacle for my english? my grammar was too terrible😂

dfahlander commented 2 years ago

Check if IndexedDBShim is included. Try remove it. If you'd still need IndexedDBShim, make sure to transpile the code to ES2016 or ES2015.

No problem with your English :)

jawalkwan commented 2 years ago

Ok, I will try it later and give the feedback to you when it still don't work Thank you so much!😉

licao404 commented 2 years ago

I had a similar problem, Sentry sounds the alarm: "InvalidStateError: Failed to execute 'abort' on 'IDBTransaction': The transaction has finished."

my environment: Electron Version:13.1.7. my Dexie.js version: 3.0.1.

help me please,it's very urgent, thx @dfahlander

jawalkwan commented 2 years ago

@licao404 我按大佬的方法试了还是没啥用,现在已经转sqlite了,因为项目比较急,没时间研究,所以兄弟你要不要也先用sqlite试试,这个库好像在electron下有点纠结😂

licao404 commented 2 years ago

@delayhsiao 好像也不是这个库独有的问题,这个库你用的是哪个版本,我看其他indexdb库下也有类似的issues,评论基本上说是浏览器内核的bug。难搞啊

jawalkwan commented 2 years ago

@delayhsiao 好像也不是这个库独有的问题,这个库你用的是哪个版本,我看其他indexdb库下也有类似的issues,评论基本上说是浏览器内核的bug。难搞啊

我用的最新版,反正大家都在吹indexeddb,但是我发现这玩意儿就跟h5早期状态一样,各家都有不同的支持状态。所以我现在转了sqlite3,用得很流畅,性能什么的,反正单机给个loading让它转就完事儿了

licao404 commented 2 years ago

I had a similar problem, Sentry sounds the alarm: "InvalidStateError: Failed to execute 'abort' on 'IDBTransaction': The transaction has finished."

my environment: Electron Version:13.1.7. my Dexie.js version: 3.0.1.

help me please,it's very urgent, thx @dfahlander

I don't know if it's similar to these issues :

@dfahlander

dfahlander commented 2 years ago

Can you confirm whether IndexedDBShim is being used or not? If IndexedDBShim is used, you must either avoid using async/await or transpile your code to ES2016 (or ES2015 or ES5) in order to avoid native async/await as it will not work with IndexedDBShim.

In order to use Dexie in node (Electron main process is a node process), IndexedDBShim can be used as an adapter between the IndexedDB API and SQLite, but IndexedDBShim has the same issues as browsers used to have historically - it won't keep transactions alive between micro ticks.

ArcherGu commented 1 year ago

same problem and no solution 😢

superocky commented 1 year ago

Using the put method and abandoning the update method can solve the problem. Currently I am using this solution

dfahlander commented 1 year ago

@superocky & @ArcherGu Are you in a browser platform, Electron or is this happening in node based unit tests (using IndexedDBShim or fakeIndexedDB to run tests in node)? What's your user agent & version? It would also help if someone could create a repro of this problem or else pin point the platforms where this happens.

the-didi commented 11 months ago

some problem