vs [email protected]
npm add [email protected]
This release adds more robust offline support to Replicache.
You can try the new offline support at https://replicache-todo-nextjs-git-replicache13-rocicorp.vercel.app/. Open in two tabs, go offline, and make changes. You’ll see your changes sync between tabs.
<aside> ⚠️ This support required some breaking API and protocol changes. You will have to make changes to your backend database schema to update to v13.
Recall that a Replicache client is a single instance of the
In previous versions of Replicache, each client (i.e., each tab) syncs completely independently with the server — there is no connection at all between clients. Two clients in the same browser have the same relationship as clients on two different computers.
To prevent each new client having to download its entire initial state from scratch, there is one exception to this separation: when a client first starts, it forks its initial state from the persisted state of some previous client.
In prior Replicache releases, new clients forked from existing ones, but afterwards were independent.
This is a nice simple design, and has the important benefit that one tab never has to coordinate with any other tab. This allows Replicache to run completely in memory, providing interactive (60fps) performance suitable for backing key strokes, mouse movements, etc. Prior Replicache releases do periodically persists in-memory state to local storage, but that persistence never blocks the UI.
In order to implement true offline support, where data replicates across tabs even while offline, Replicache 13 introduces the new concept of Client Groups.
In Replicache 13, all clients within a client group share the same persistent storage.
Replicache clients with the same
name share a single group. Replicache still runs purely from memory, but behind the scenes, it synchronizes with a local storage area that is shared between all clients in the group. This is how changes from one tab replicate to other tabs, even when offline.