A Zustand store gets its saved state from asynchronous storage. Start restoring the saved state, then clear storage before the pending read or migration finishes. When that work eventually completes, it can still overwrite the current state and tell listeners the restore finished.
Update the persistence behavior so clearing storage invalidates any restore already in progress.
- A pending storage read or migration must leave live state alone after the clear and must not report successful hydration.
- Clearing storage must preserve the current live state even if it was hydrated earlier.
- If removing storage throws synchronously, let that exception reach the caller. The pending restore should remain invalid.
- A later restore should continue to work normally.
Reproduce the behavior and add a focused test for your change. Run the repository's existing persistence tests before submitting.
f44cecc72a8e (pmndrs/zustand 5.0.14). Grading uses hidden tests for the fix and existing behavior.An upstream fix is publicly available. An assistant may already recognize this task. For a cold rehearsal, pick another exercise if you know the fix.