set subs to not ready on disconnect #128
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
I'm still not really happy with how the tracker behaves, especially after disconnects. I found out two things:
connected
event, all stale data is removed from all collections.disconnected
event, all subs remain inready
state.This results in the following: Say you disconnect from your server once your app is sent to background. When you bring your app back to foreground, the connection is reestablished and all docs get removed and then initially added again. During all this, all sub handlers are in
ready === true
state. Ultimately, this leads to flashing UI and bad UX, since in the normal UI design pattern you pick up any sort of loading / refreshing state fromhandle.ready()
.I already tried to work around to somehow get rid of no 1 (eg. only remove stale docs or something similar). But actually we know that no matter how you implement this part, you need to transfer all the changes / removals that happened during your offline-time from the server. But, of course, in this case, you definitely should be able to inform your user about a reloading state in your UI instead of just removing all docs in front of his eyes and then re-adding them.
This PR implements a more canonical behavior of the ready state of subs when a disconnect happens. In this case, all subs are flagged as not ready. So if you (re)connect, they will simply reload, and all handlers will report that accordingly.
Using this, you can then easily implement an offline-first version of
useTracker
, that stores tracker results eg. in AsyncStorage, once the corresponding sub is ready and fetches data offline first, if the app is not connected or the sub is not ready yet, and displays live data once the sub is ready. I'm currently testing this on iOS and even on Edge networks this leads to a really responsive UI.I also tried to put the new LOC marking subs as not-ready in the
Meteor.disconnect()
method, but of course then you miss disconnections coming from the server side.