vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.72k stars 996 forks source link

ref takes Object inheriting Map and returns Map object #2704

Closed jmarshall9120 closed 3 weeks ago

jmarshall9120 commented 3 weeks ago

Reproduction

https://play.pinia.vuejs.org/#eNqNVG1r2zAQ/ivCX+xAIq90dBCS0L10sEG3se7bPIprXVJ18klIsput5L/vJMeum4VSCM757rm75x759JC8NYa3DSTzZOEqK41nDnxjmCpxsywS74pkVaCsjbaePbDGwZXXFtiOra2uWcrzSjfowXLv0hFQ42X0ix5ITSheYKXRUZNYZDnUyyYhNiRl2WS5eiiQdUDuwflrC+vrtlTNHryLzwIXeUecaNKLh9qo0gO9MbYQsl0t8vAMuFEsmSYd1VldGn7nNJICsWGxD9DgcxY9wWckyjJ4iiSPNgdXz26svnc0+h2Bpz30nCbNBbRea+VmpZFd2q33xs3zvBJIeAFKtpYj+BxNnf+Xc37Gz/hJruRNTo1yiQK2T9tQxkxA/ZLqPfT8FT95zd/Equ3pvmgdqoaiO5KUZPGOTmgtNweiVLo2UoH9arykE3wiTqmUvv8cfd42MFCsbqH6fcR/57Yd628WSL4WRmP50m7Ad+GLqy+wJXsI1lo0itDPBL+D06oJHDvYuwYF0R7hIttP8Ywlbn64i60HdP1QgWhUI+KjzO+fGf2R7ik/Han4uBQk4bAUAtYSDxYofk3jzaHPfAgOS6NK59iH0peXpWE0N6BwLNiRSdwp21RUOOOcEyc3L/HPz1+TnqlrDAwxWpxIlLG11tlkzlotRY8MtbQCrvQmSz9qzSoSDASlpn0e/QqEbeTbrfNwLSzHM2bpXoZ0yrIJW65GbBkSlkZd7IdaZQj3/YTZJO428WuwCqKzwwvgGFmcs3SKkeRhhMc0CrO9eRzl5F9IWQAF6zgmShYadVavSfizdHNapCPE6QHhqBpBk90/QvnTzA==

Steps to reproduce the bug

Check the console output and the typescript errors in the reproduction.

Expected behavior

Doing this:

class DataObject extends Map{
    constructor(){
        super()
    }
}
const MyRef = ref(new DataObject())
console.log(MyRef.value)

Should return a DataObject not a Map object.

Actual behavior

The passed in DataObject is lost an a Map object is returned.

Additional information

No response

posva commented 3 weeks ago

You are just missing a .value. Note that if you do SSR, you will need a custom serialization to handle custom types with devalue: https://github.com/Rich-Harris/devalue (in Nuxt payload plugins). BTW I go through both in depth in my Mastering Pinia course

jmarshall9120 commented 3 weeks ago

@posva - The missing .value is a typo on my part. I see with it, the reproduction works, but my local repo still does not. Very inconvenient typo to make the reproduction and my actual project line up when they don't. I'm gonna see if it is the devalue issue. It could be that the parent Map serializes and deserializes back to a map. That's a good thought. Will test that now.