pinia
pinia copied to clipboard
acceptHMRUpdate skips optional attributes without default values
Reproduction
https://github.com/bodograumann/pinia-hmr-optional-attributes
Steps to reproduce the bug
-
git clone https://github.com/bodograumann/pinia-hmr-optional-attributes
-
cd pinia-hmr-optional-attributes
-
npm install
-
npm run dev
-
xdg-open http://localhost:5173
- Press the "Increment" button. Sign says "positive".
-
touch src/store/counter.ts
Expected behavior
All the state should be preserved.
Actual behavior
counter.nr
is preserved as 1
, but counter.sign
is lost. The page shows -
, while it should show positive
.
Additional information
The relevant code is here: https://github.com/vuejs/pinia/blob/93b5546cf18bc54bb90de2397219dec7360fa697/packages/pinia/src/hmr.ts#L41-L43
The problem is that the removal of the property sign could be intentional so I'm not sure if this is with changing as it would break other HMR cases.
In order to change this behavior, one could get each property with toRaw(newStore.$state)
and check if the property is a ref in order to completely replace it rather than patchObject
Sounds to me like your proposed solution would keep the other use case of removing a property intact, right? I think it should also work for us. Normally I would be happy to contribute a PR, but given that my previous PR is still open and we are thus unable to use the latest pinia version, I am not sure how to proceed here :neutral_face:
I do need to check that PR. Currently we wonβt be able to release a new version of pinia soon because of other changes π₯²