Open
Description
Reproduction
https://codesandbox.io/p/devbox/competent-feather-24dw95
Steps to reproduce the bug
- Create a store with object state and an action
- Change that state in component through interaction
- Update your action's code
- Observe that the state was reset to a default one
Expected behavior
State should be preserved.
Actual behavior
State is reset to a default value.
Additional information
The bug happens with Vue 2 and Vite. Not sure if it also applies to Vue 3 due to different reactivity systems.
Activity
posva commentedon Mar 10, 2025
I cannot reproduce with updated dependencies locally. This might be an issue with Vue 2 (deprecated), in which case, you will need to check for Vue 2 support
CyberAP commentedon Mar 10, 2025
@posva how did you reproduce? I forked the codesandbox to use Vue 3 + latest Pinia. Issue is still there.
Screen.Recording.2025-03-10.at.13.02.24.mov
[-]State is not preserved with HMR[/-][+]Plain objects states are reset during HMR[/+]posva commentedon Mar 10, 2025
I tested locally with an empty vite project
pnpm create vue
with both setup and option stores. It does work with numbers and Maps but you are right, it doesn't work with an object like in your example.It might not be feasible to keep everything consistent with this case but feel free to give it a try! check the store.ts file and search for the _hotUpdate function