earthstar-project / react-earthstar

A UI toolkit for making collaborative, offline-first applets for small groups.
GNU Affero General Public License v3.0
60 stars 5 forks source link

Add internal FocusSyncer component #59

Closed sgwilym closed 3 years ago

sgwilym commented 3 years ago

Recently I noticed that, when reopening a tab with a react-earthstar app, workspace data would be missing new documents that were created since putting the tab in the background. This is especially noticeable on a phone.

What I've added here is an internal component which kicks off a manual sync for all workspaces when a tab is refocused.

This only happens if EarthstarPeer's isLive state is true.

cinnamon-bun commented 3 years ago

Aha, yes, this is a conceptual bug with the sync algorithm.

Currently, live sync opens a steam of new events from the server. It should open a stream of events since a given time, so it can recover from gaps. The server-sent events spec has a way to handle this, Last-Event-Id, which we're not using yet.

For now the only way to recover from gaps is to do a full sync again.

This PR is a reasonable fix until the core sync algorithm is fixed, I support it 👍

Various thoughts: