mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
* feat(react): implement getServerState by closing over the defaultState serverState will be used by react on the first client render; this should avoid hydration mismatches when combined with the persist middleware, which can change the state between the SSR and the first CSR * define getServerState in vanilla.ts * feat: implement getServerResult in persist middleware this avoids hydration errors when state is restored from e.g. localstorage synchronously * feat: capture initialState for getServerState in react this avoids hydration mismatches when updates happen to the store state between ssr and csr * refactor: revert changes to oldImpl * fix: make selector default to identity function if we default to `api.getState`, we will always read the client snapshot if there is no selector passed. An identity function returns its argument, which is either the snapshot (api.getState) or the server snapshot (api.getServerState) * define getInitialState in vanilla * revert WithReact * fix them * fix test * oops, fix another test too * forgot to use identity * test: add a test for hydration errors * fix(readme): imply getInitialState is a public api --------- Co-authored-by: daishi <daishi@axlight.com>