fix(sync): block patches before initial hydration

This commit is contained in:
Richard 2024-09-20 01:38:53 -07:00
parent f0acadb4e6
commit d682efa94e

View file

@ -31,11 +31,20 @@ type ClientSyncer = {
local function client(options: ClientOptions): ClientSyncer
local atoms = options.atoms
local self = {} :: ClientSyncer
local ready = false
-- Apply the state changes sent by the server.
function self:sync(...)
for index = 1, select("#", ...) do
local payload = select(index, ...)
local payload: SyncPayload = select(index, ...)
if payload.type ~= "init" and not ready then
-- If the client has not been hydrated yet, ignore patches.
-- This is to prevent the client from patching incomplete state.
continue
end
ready = true
store.batch(function()
for key, state in next, payload.data do