Open achou11 opened 2 months ago
Thinking about this more, you could invalidate queries on completing or stopping sync (outside the context of screens that have mounted) for a more long-term solution.
I investigated this a bit more today.
beforeRemove
eventThe current sync query invalidation is probably causing a race condition that explains the behaviour observed in QA. Stopping sync is an asyncronous operation. What I think is possibly happening:
project.$sync.stop()
queryClient.invalidateQueries({queryKey: [OBSERVATION_KEY]});
The conditions for this are going to be device-dependent. I would expect indexing to start quite soon after a device receives data from sync, but it's conceivable that there is a delay maybe by sync occupying the event loop. It would depend on timing for when the user exits the sync screen after sync and how much data is syncing and how fast their device is.
I think a solution to this is to invalidate the queries once sync is in the stopped state. Although even more robust solution would also be to invalidate queries whenever syncing is completed (in case we decide in the future to not stop sync when we leave the screen). This listener ideally sits outside any component (e.g. in the sync store), but is ok to have in the sync screen for now.
Separately I think it would be useful to add a lot more debugging info to Sentry so we can determine the order of events for stuff like this.
We currently don't invalidate any query caches when data is updated (in the background) via syncing. This leads to cases where certain parts of UI are outdated because they are displaying stale data. An example of this happening is navigating to screens that are part of the same stack navigation (e.g. the map) as the sync screen after syncing
Short-term suggestion is to invalidate all relevant queries when leaving the sync screen.