Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

toArray() returns empty array on first call, works as expected on second call

Open princefishthrower opened this issue 3 years ago • 5 comments

I've got a very strange issue here: the following Dexie code:

const myTableArray = await db.table("myTable").toArray()
const myTableArraySecond = await db.table("myTable").toArray()
console.log(myTableArray)
console.log(myTableArraySecond)

will output the following:

[]
[{<<expected rows>>},{<<expected rows>>},{<<expected rows>>}]

Obviously I expect the second output in both console.logs(), but somehow the first call always returns an empty array!

The code in my application is exactly as above; the two toArray() calls are right next to each other. It's almost like there is an init or registering step that takes place by calling the first toArray(). Has anyone seen behaviour like this and have any pointers?

princefishthrower avatar Apr 13 '21 11:04 princefishthrower

Never seen this or heard of any similar issue. A repro would be very good if possible.

dfahlander avatar Apr 13 '21 19:04 dfahlander

@princefishthrower If you do console.log(db) before any of that code, is your database null? I wonder if it's not initializing properly.

cliftonlabrum avatar Apr 16 '21 00:04 cliftonlabrum

Which version use? I have do this (https://jsfiddle.net/DevShoesed/gp9y1usr/1/) an example and first and second call are the same.

DevShoesed avatar Aug 28 '21 12:08 DevShoesed

Experiencing this as well. Any pointers on why that could be the case? Does the state needs to be flushed to disk?

noway avatar Nov 17 '21 10:11 noway

Please give us a repro. As @DevShoesed posted, https://jsfiddle.net/DevShoesed/gp9y1usr/1/ gives the same results in both first and second. Also: Dexie version and which browser would be important information.

dfahlander avatar Nov 17 '21 11:11 dfahlander