rocicorp / repc

The canonical Replicache client, implemented in Rust.
Other
31 stars 7 forks source link

We need to correctly implement IDBStore onversionchange #161

Open aboodman opened 4 years ago

aboodman commented 4 years ago

Currently it is difficult to use the drop API correctly in Replicache. Users must ensure that all connections to the same named replicache instance (across all tabs!) first close their connections. This is because of that is what the underlying idbstore requires.

See: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#Version_changes_while_a_web_app_is_open_in_another_tab and https://twitter.com/aboodman/status/1301969990904475648.

I thought that we don't need to implement the version change dance of IDB because we don't ever change our IDB schema. However we do expose dropping the database through the API which counts as a version change. Also the user can drop the DB through Chrome's dev tools UI which might also count (should check).

Luckily we abstract all the away from our user, so we can just implement onversionchange to close and re-open the db.

arv commented 4 years ago

We talked a bit about this and our understanding is that we need to close the IDBDatabase to "confirm" drops happening out of bounds.

This close needs to be routed back to the js sdk. It can be done with a callback or by returning a specific error when incove is called. Then JS can cleanup its state (subscriptions etc).

aboodman commented 4 years ago

Is this done @arv?

arv commented 4 years ago

I think there was a reason why I marked it as towards instead of closes... but I cannot recall. I think we talked about routing back the close to the Replicache object but at the moment all the dispatch calls will fail and we do not really distinguish the different flavors of errors.

I think I wanted to deal with db is closed errors in the bindings and that was why I kept this open.