-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Collection not reactive in useTracker in core version 2.5.0 #122
Comments
it broke already at release 2.4.0 |
Seems to be introduced in #111 the big question is, by which part of it. @ToyboxZach can you help out with this? Maybe we can fix this one together? I'd like to write some tests, would you mind taking a look at the reproduction repo and your former pull request and find out, what change this actually caused? |
It can be fixed in the local collection by using LocalCols insert and update methods rather than going for minimongos upsert directly. Eg by turning this
into this
I'll propose a PR on this. Fixes the issue. But tests for this seem a good idea to make things future proof. However, as the local collection hasn't changed in #111 , it seems like the trackers behavior did since it now does no longer catch up with modifications on minimongo. Question is, whether this is a wanted or unwanted behavior. |
In any case we definitely need better test coverage for collection reactivity |
Interestingly, if you try to add a "removed" observer to the |
Do I assume correctly, that #123 would require some additions in order to resolve reactivity with remove? |
Yeah sorry, my use cases doesn't utilize any local collections so I wasn't focused on it, I was dependent on the tests to work so there is a good chance I missed triggering the tracker for a lot of cases of local handling |
Actually not, that's why I'm surprised. |
I think the problem is the original code was using _collection, which was not setup to utilize the new tracker infrastructure, switching to the normal .insert/.update functions will make it work the same way as the remote collections, so I would expect this to work. Honestly I'm not quite sure what the purpose of the separate Local.Collection is vs just using the Mongo.Collection without a name, which is how normal meteor mongo creates local collections. My suggestion would be to remove Local.Collections completely and fix any issues that come up in Mongo.Collection where we aren't pushing the right reactivity |
I guess nameless Mongo collections only live in memory. Local collections use async storage and get updated automatically as soon as ddp is reconnected. I use this to get my app offline first ready. However, local collections don't recognize removed documents. Guess this is due to the fact that when coming back, initially docs are added (current state from the pub) but nothing "old" is removed. That's why I suggested something like "stale" local documents, that could be old local documents that don't exist on the server anymore and could be removed from the client after a reconnect. |
Hmm that behavior seem like it should instead be an option on meteorrn/minimongo , but IMO the better solution would be for each app to handle that, since what I see in LocalCollection doesn't feel like a general solution. I think a basic implementation would be:
|
I personally consider "offline first" a quite general feature / approach that you might want in your app. Get data from the server, keep it on device, update asap. Hence, it's legit to have this in a package. @ToyboxZach s example shows how everyone would struggle with all possible situations; for instance this implementation would not work on a disconnect, or what if you reopen the app without a connection? |
Ok, maybe you've got a point there @ToyboxZach . Tried to get a conceptual solution for an offline first approach by trying to patch things in Local.Collection and the tracker (cf. my draft PR #124), but that's somewhat hacky. I now created a "useCachedTracker" wrapper for "useTracker" that handles offline caching quite nicely; if you're offline or the sub is not ready yet, offline data is used, otherwise "live" data. |
|
@bratelefant @ToyboxZach can we generalize this a bit? From my perspective I see the following:
To me this is an attempt for at least a new minor release. What do you think @bratelefant @ToyboxZach ? |
IMO the most important thing is to make the behavior really predictable. Right now, based on the current release of This results in really speedy ui, while preserving full reactivity. But it's crucial, that the "subReady" event and connection status are really on point. I observed that sometimes (especially when bringing up the app from background) docs get removed and added again (although they didn't change serverside), while the sub is still "ready". |
I think this fits for the above specs. The "strategies" are only an idea, in case we may have conflicting use-cases.
I think we need a reproduction repo where we can investigate this. Can you recreate this issue by any chance? |
Each of these use-cases can occur while being online or offline; eg. in flight-mode or online but the server is not reachable.
That's basically it I guess. Key point is that DDP doesn't send "remove" or "update" events to the client for all changes that occured since the last disconnect, if I got it right... (at least this would be reasonable to do it like that, since there could possibly a lot of stuff to catch up with on the client) Is there any way to get the exact point from DDP on where the point of "once all added" is reached? This would be the golden path for the EDIT: If the |
You can eg get your meteorrn starter repo or any minimal repo and add a "disconnect" / "reconnect" button and observe the "ready" state of a sub handler, and also eg log "added" events of an arbitrary collection that fetched data via this sub. The sub will constantly be "ready". Cf #128 |
Closing this issue due to no activity. Feel free to reopen. |
If you use the Local Collection (like
new Local.Collection("tasks")
instead ofnew Mongo.Collection("tasks")
), useTracker will not be triggered on an "added" or "changed" event.I recreated this behaviour in a fork of the repo meteor-react-native-starter
The text was updated successfully, but these errors were encountered: