Skip to content

Plain objects states are reset during HMR #2931

Open
@CyberAP

Description

@CyberAP
Contributor

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

Activity

posva

posva commented on Mar 10, 2025

@posva
Member

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

CyberAP commented on Mar 10, 2025

@CyberAP
ContributorAuthor

@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
changed the title [-]State is not preserved with HMR[/-] [+]Plain objects states are reset during HMR[/+] on Mar 10, 2025
added
has workaroundThe issue contains a temporary solution to get around the problem
HMR 🔥Related to Hot Module Replacement
on Mar 10, 2025
posva

posva commented on Mar 10, 2025

@posva
Member

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

reopened this on Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HMR 🔥Related to Hot Module Replacementcontribution welcomehas workaroundThe issue contains a temporary solution to get around the problem✨ enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @posva@CyberAP

      Issue actions

        Plain objects states are reset during HMR · Issue #2931 · vuejs/pinia