async migrate
will result in Data Loss
#2827
Unanswered
KiwiKilian
asked this question in
Bug report
Replies: 1 comment 1 reply
-
Thanks for reporting. Nice catch. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug Description
Using an
async migrate
function withpersist
does not set the result as the store value and resets to the initial state. See this store withasync migrate
:And compare to this non-async
migrate
:When there is a persisted value in the storage and raising the
version
to2
the console will show the correctly migrated valueasync migrate result {"example":"migrated ✅"}
but the store will not accept it and reset to the initial value. This can be produced by following the steps in the linked example:0. Initially displayed
Result:
1. Click Button to initially persist stores
Result:
2. Manually change version in both stores to 2
Result:
→ Both stores should have changed the value to
migrated ✅
but theasync
will fallback toinitial
This is broken from >= 4.5.5 upwards (I've reproduced with 4.5.5, 5.0.0 and 5.0.1), similarly to the behavior change #2763 I suspect #2678, to have broken this functionality.
If I'm not doing something wrong this should be quite prominently announced. People are facing data loss, if they have an
async migrate
and it's executed using any of the affected versions. It might even be a case for a security advisory.Reproduction Link
https://stackblitz.com/edit/vitejs-vite-jd3xf5?file=src%2FuseAsyncStore.ts
Beta Was this translation helpful? Give feedback.
All reactions