dexie / Dexie.js

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

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

Open princefishthrower opened 3 years ago

princefishthrower commented 3 years ago

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?

dfahlander commented 3 years ago

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

cliftonlabrum commented 3 years ago

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

DevShoesed commented 3 years ago

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

noway commented 3 years ago

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

dfahlander commented 3 years ago

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.