Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plain objects states are reset during HMR #2931

Open
CyberAP opened this issue Mar 10, 2025 · 3 comments
Open

Plain objects states are reset during HMR #2931

CyberAP opened this issue Mar 10, 2025 · 3 comments
Labels
contribution welcome ✨ enhancement New feature or request has workaround The issue contains a temporary solution to get around the problem HMR 🔥 Related to Hot Module Replacement

Comments

@CyberAP
Copy link

CyberAP commented Mar 10, 2025

Reproduction

https://codesandbox.io/p/devbox/competent-feather-24dw95

Steps to reproduce the bug

  1. Create a store with object state and an action
  2. Change that state in component through interaction
  3. Update your action's code
  4. 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.

Screen.Recording.2025-03-10.at.11.57.47.mov
@posva
Copy link
Member

posva commented 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

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2025
@CyberAP
Copy link
Author

CyberAP commented 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

@posva posva changed the title State is not preserved with HMR Plain objects states are reset during HMR Mar 10, 2025
@posva posva added ✨ enhancement New feature or request has workaround The issue contains a temporary solution to get around the problem HMR 🔥 Related to Hot Module Replacement labels Mar 10, 2025
@posva
Copy link
Member

posva commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome ✨ enhancement New feature or request has workaround The issue contains a temporary solution to get around the problem HMR 🔥 Related to Hot Module Replacement
Projects
None yet
Development

No branches or pull requests

2 participants