SIGN IN SIGN UP
pmndrs / zustand UNCLAIMED

🐻 Bear necessities for state management in React

0 0 40 TypeScript

fix(persist): prevent race condition during concurrent rehydrate calls (#3336)

* fix(persist): prevent race condition during concurrent rehydrate calls

  Added hydrationVersion counter to track and invalidate stale hydrations.
  When multiple rehydrate() calls happen concurrently, only the last one
  applies its state, preventing race conditions with async storage.

  - Added hydrationVersion counter incremented on each hydrate() call
  - Added version checks after each async step (getItem, migrate, set)
  - Added 3 tests for concurrent rehydration scenarios

* fix(persist): refactor simplify hydration abort logic

* fix(persist): refactor use consistent comment pattern for abort checks

* fix(persist): refactor remove redundant abort checks

* fix(persist): refactor remove unnecessary migrationResult check

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
N
Niyaz committed
d0cb549ff67ab2ecc62202a5d261f4cffcedb9f4
Parent: 59e8783
Committed by GitHub <noreply@github.com> on 1/12/2026, 5:52:32 AM