Seb-L / pinia-plugin-persist

Persist pinia state data in sessionStorage or other storages.
https://Seb-L.github.io/pinia-plugin-persist/
MIT License
214 stars 37 forks source link

trap returned falsish for property #67

Closed cgrisar closed 1 year ago

cgrisar commented 1 year ago

Thank you for a great plugin.

May I suggest to adapt the docs according to a bug I had last night?

I write my vues, including the pinia stores along the script setup syntax

So, I was struggling a few hours on a

'set' on proxy: trap returned falsish for property bug

The property that lifted the error was a getter (computed, read-only).

Using

{
    persist: {
        enabled: true
    }
}

will persist all the variables, including the getters.

Navigating from page to page or refreshing a page will try to set a getter though a getter is read-only.

Solution:

you must use strategies and restrict the variables that are persisted with path (and avoid having a getter in the path)

{
    persist: {
        enabled: true,
        strategies: {
            path: ['state_variable_1', 'state_variable_2', '...] // avoid getter in the list
         }
     }
}