Skip to content
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

set subs to not ready on disconnect #128

Merged
merged 3 commits into from
Sep 11, 2023

Conversation

bratelefant
Copy link
Collaborator

Hi all,

I'm still not really happy with how the tracker behaves, especially after disconnects. I found out two things:

  1. On a connected event, all stale data is removed from all collections.
  2. On a disconnected event, all subs remain in ready 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 from handle.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.

@jankapunkt jankapunkt merged commit 6d3a3e9 into meteorrn:dev Sep 11, 2023
9 checks passed
@jankapunkt jankapunkt mentioned this pull request Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants