dumbmatter / fakeIndexedDB

A pure JS in-memory implementation of the IndexedDB API
Apache License 2.0
564 stars 69 forks source link

Regress: undefined entry during iterating records #53

Closed mnasyrov closed 4 years ago

mnasyrov commented 4 years ago

The 3.1.0 version introduced a regress bug. The previous 3.0.2 works OK.

I have the following deletion using Dexie.js (3.0.1 version):

db.table('some-table')
  .where('key')
  .startsWith('some-prefix)
  .delete();

It produces the next error:


Error: Could not delete some values. Errors: TypeError: Cannot read property 'key' of undefined

    at /testproject/node_modules/dexie/src/classes/collection/collection.ts:586:36
    at /testproject/node_modules/dexie/src/helpers/promise.js:843:23
    at callListener (/testproject/node_modules/dexie/src/helpers/promise.js:497:19)
    at endMicroTickScope (/testproject/node_modules/dexie/src/helpers/promise.js:583:25)
    at /testproject/node_modules/dexie/src/helpers/promise.js:652:30
    at done (/testproject/node_modules/dexie/src/dbcore/dbcore-indexeddb.ts:194:11)
    at FDBRequest.req.onerror (/testproject/node_modules/dexie/src/dbcore/dbcore-indexeddb.ts:204:11)
    at invokeEventListeners (/testproject/node_modules/fake-indexeddb/build/lib/FakeEventTarget.js:67:31)
    at FDBRequest.Object.<anonymous>.FakeEventTarget.dispatchEvent (/testproject/node_modules/fake-indexeddb/build/lib/FakeEventTarget.js:120:13)
    at FDBTransaction.Object.<anonymous>.FDBTransaction._start (/testproject/node_modules/fake-indexeddb/build/FDBTransaction.js:214:29)
    at processImmediate (internal/timers.js:456:21)
From previous: 
    at DexiePromise.then (/testproject/node_modules/dexie/src/helpers/promise.js:182:22)
    at /testproject/node_modules/dexie/src/classes/collection/collection.ts:585:12
    at /testproject/node_modules/dexie/src/helpers/promise.js:843:23
    at callListener (/testproject/node_modules/dexie/src/helpers/promise.js:497:19)
    at endMicroTickScope (/testproject/node_modules/dexie/src/helpers/promise.js:583:25)
    at FDBRequest.onsuccess (/testproject/node_modules/dexie/src/helpers/promise.js:652:30)
    at invokeEventListeners (/testproject/node_modules/fake-indexeddb/build/lib/FakeEventTarget.js:67:31)
    at FDBRequest.Object.<anonymous>.FakeEventTarget.dispatchEvent (/testproject/node_modules/fake-indexeddb/build/lib/FakeEventTarget.js:120:13)
    at FDBTransaction.Object.<anonymous>.FDBTransaction._start (/testproject/node_modules/fake-indexeddb/build/FDBTransaction.js:214:29)
    at Immediate.<anonymous> (/testproject/node_modules/fake-indexeddb/build/lib/Database.js:26:26)
    at processImmediate (internal/timers.js:456:21)
From previous: 
    at Object.mutate (/testproject/node_modules/dexie/src/dbcore/dbcore-indexeddb.ts:120:14)
    at Object.mutate (/testproject/node_modules/dexie/src/hooks/hooks-middleware.ts:52:28)
    at /testproject/node_modules/dexie/src/classes/collection/collection.ts:584:33
    at /testproject/node_modules/dexie/src/helpers/promise.js:843:23
    at callListener (/testproject/node_modules/dexie/src/helpers/promise.js:497:19)
    at endMicroTickScope (/testproject/node_modules/dexie/src/helpers/promise.js:583:25)
    at FDBRequest.onsuccess (/testproject/node_modules/dexie/src/helpers/promise.js:652:30)
    at invokeEventListeners (/testproject/node_modules/fake-indexeddb/build/lib/FakeEventTarget.js:67:31)
    at FDBRequest.Object.<anonymous>.FakeEventTarget.dispatchEvent (/testproject/node_modules/fake-indexeddb/build/lib/FakeEventTarget.js:120:13)
    at FDBTransaction.Object.<anonymous>.FDBTransaction._start (/testproject/node_modules/fake-indexeddb/build/FDBTransaction.js:214:29)
    at Immediate.<anonymous> (/testproject/node_modules/fake-indexeddb/build/lib/Database.js:26:26)
    at processImmediate (internal/timers.js:456:21)
dumbmatter commented 4 years ago

Thanks, I'll try to get to this this week. If you have a self-contained reproduction (ideally without Dexie, but even with Dexie is fine) that would be helpful :)

mnasyrov commented 4 years ago

I made a test case with Dexie: https://codesandbox.io/s/frosty-platform-nh4ve?file=/src/fidb.test.js

dumbmatter commented 4 years ago

Thank you @mnasyrov for the bug report and for the minimal reproduction, that was very helpful! I fixed it in v3.1.1.

@nolanlawson - just tagging you in case you're curious, since the bug was in your recent PR, but I think I handled it :)

nolanlawson commented 4 years ago

@dumbmatter Ah, sorry about that! I was mostly relying on the test cases to catch everything; sorry that I introduced the regression!