From d682efa94e31ec9f9b97560f12a01178fc7d4875 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 20 Sep 2024 01:38:53 -0700 Subject: [PATCH] fix(sync): block patches before initial hydration --- src/sync/client.luau | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sync/client.luau b/src/sync/client.luau index ce6993e..284660c 100644 --- a/src/sync/client.luau +++ b/src/sync/client.luau @@ -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