jamauro / offline

An easy way to give your Meteor app offline capabilities and make it feel instant
13 stars 1 forks source link

No offline cache of the `Meteor.users` collection #5

Closed wildhart closed 1 month ago

wildhart commented 1 month ago

Thanks for making this package - it looks awesom from my quick play with it!

Is there a reason why there isn't an indexedDB for the Meteor.users collection?

If I'm logged in, disable the network in DevTools, and then refresh the browser, the app loads as if the user is off-line because all my menu items are hidden from non-authenicated users. I would like my PWA to be able to load while off-line.

In the console:

> Meteor.userId()
< 'xcL2z37pXn4ekbTDz'
> Meteor.user()
< undefined
> Meteor.users.find().fetch()
< []

If I call Meteor.users.keep() I get this error: Error loading collections DOMException: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.

jamauro commented 1 month ago

Thanks for opening this issue. Preserving Meteor.user() sounds like a good feature. I’ll take a closer look soon.

wildhart commented 1 month ago

I think if you cache the Meteor.users collection for off-line use, then Meteor.user() would just work because internally it just performs Meteor.users.find(Meteor.userId()).fetch()

There are other reasons why I, and presumably other developers, would benefit from the Meteor.users collection being cached off-line. For example, I would like my user to be able to select from a list of other users - these users are provided by a collection so not currently cached off-line.

Is there a reason why the Meteor.users collection is not available off-line? Could it be possible?

jamauro commented 1 month ago

I just published v0.2.0 which persists Meteor.users by default 🎉. This should enable the behavior you were hoping for. Let me know how it goes.

wildhart commented 1 month ago

This works perfectly for me so far, thank you!