Skip to content

Commit 6d046fe

Browse files
committed
feat: implement getServerResult in persist middleware
this avoids hydration errors when state is restored from e.g. localstorage synchronously
1 parent 1ddd6fc commit 6d046fe

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/middleware/persist.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ const oldImpl: PersistImpl = (config, baseOptions) => (set, get, api) => {
271271
api,
272272
)
273273

274+
api.getServerState = () => configResult
275+
274276
// a workaround to solve the issue of not storing rehydrated state in sync storage
275277
// the set(state) value would be later overridden with initial state by create()
276278
// to avoid this, we merge the state from localStorage into the initial state.
@@ -425,6 +427,8 @@ const newImpl: PersistImpl = (config, baseOptions) => (set, get, api) => {
425427
api,
426428
)
427429

430+
api.getServerState = () => configResult
431+
428432
// a workaround to solve the issue of not storing rehydrated state in sync storage
429433
// the set(state) value would be later overridden with initial state by create()
430434
// to avoid this, we merge the state from localStorage into the initial state.

0 commit comments

Comments
 (0)