earthstar-project / earthstar

Storage for private, distributed, offline-first applications.
https://earthstar-project.org
GNU Lesser General Public License v3.0
632 stars 20 forks source link

Replicas should wait for ReplicaDriverIndexedDB to be ready #235

Closed basham closed 2 years ago

basham commented 2 years ago

If you have a replica configured with ReplicaDriverIndexedDB, there isn't a guarantee that the database is ready when you initially call a method on it.

For example, even though I have set a particular doc and know it is there, this will return undefined soon after page load.

const doc = await replica.getLatestDocAtPath('/doc.txt')

I've gotten around it first by putting in a delay. But then after digging around, I replaced the delay with an await on IndexedDB.

await replica.replicaDriver.getIndexedDb()
const doc = await replica.getLatestDocAtPath('/doc.txt')

However, it would be better if any replica methods have this await built in. It may require some new method on the drivers, that resolves a promise when the driver is ready.

sgwilym commented 2 years ago

This has been fixed as of 8.1.2!