ngx-indexed-db: Potential exception when using rxjs 7 in Angular 13
Environment:
- angular: 13.1.0
- rxjs: 7.4.0
Stacktrace:
TypeError: Cannot read properties of undefined (reading 'isStopped')
at error (Subscriber.js:35:18)
at IDBTransaction.error [as __zone_symbol__ON_PROPERTYerror] (ngx-indexed-db.js:106:13)
at IDBTransaction.B (zone.js:803:43)
at ir.invokeTask (zone.js:434:35)
at Object.onInvokeTask (core.mjs:25437:33)
at ir.invokeTask (zone.js:433:64)
at ir.runTask (zone.js:205:51)
at ir.invokeTask [as invoke] (zone.js:516:38)
at pr (zone.js:1656:18)
at IDBTransaction.Er (zone.js:1682:21)
This happens when calling getAllKeysByIndex
and it fails.
When creating the transaction obs.error
is directly passed on and I guess in rxjs7 the callback uses a this
which “gets lost” due to the closure there.
I have also seens this in other places in code. Everything here is just a guess, but maybe someone else could clarify.
I have a rather large app where I can reproduce the issue, but could not yet create a minimal repro for it.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (4 by maintainers)
Hi @HFTSOL, I hope I can take a look at the problem these days. I can’t promise you anything because this is a new issue for me
I will say, that I ended up just using https://www.npmjs.com/package/idb and just using indexeddb directly instead of through Angular, and it’s working pretty well for me. Sometimes framework-agnostic solutions are all you need.
Thanks, @noobed7 that reproduction was precise and demonstrated @cmxl initially reported, your fix suggestion was also well pointed.
Hi, as I wasn’t sure how to give a demo, I forked your repo and pushed to a new branch
https://github.com/noobed7/ngx-indexed-db/tree/break-simulation - here I tried to email you earlier this week, but it might have gone to spam. I’d like to propose a fix for this issue since it’s a trivial js closure problem.
For example
/ngx-indexed-db/src/lib/ngx-indexed-db.service.ts
in this file, this lineconst transaction = createTransaction(db, optionsGenerator(DBMode.readwrite, storeName, obs.error));
could be fixed as follows:const transaction = createTransaction(db, optionsGenerator(DBMode.readwrite, storeName, (e) => obs.error(e)));
we are capturing the error callback argument with the help of a closure arrow function. This way the proper hanler is invoked and the console is clear from unhandled exceptions
Has there been any movement on this issue? I am seeing this issue in versions 9.3 - 10 and I’m using Angular 12 and RxJs 6.6. I upgraded from 9.1.2 because of the “objectStore does not exists” bug and hit this one. I need to know if it’s going to be fixed in the next week or I have to remove the lib and replace it with something else. Thanks.