Open seepine opened 4 weeks ago
Hi, thanks for the reproduction, it helped me pin what is probably the issue.
I think it comes from the way Pinia itself handles plugins. As stated in the docs (here), Pinia plugins are applied ONLY after pinia is passed to the app. In your case, Pinia is instantiated and used before the app (you need to pass it the Pinia instance explicitely), so the persistedstate plugin is not part of it because of that.
It can be confirmed by this code from pinia, which defers plugins if there is no Vue app instance available.
I will try to investigate a bit if that can be fixed/worked around from our plugin, but I doubt it.
I can see two solutions for you:
useLocalStorage
as suggested hereHopefully this helps you a bit 🙏
Yes, I tried to customize the plugin,it cannot be applied to the store created before.
pinia.use(context => {
console.log(context)
})
Any setTimeout of pinia._s
can got all store, but this is not a good idea.
setTimeout(() => {
pinia._s.forEach(store => {
console.log(store)
})
}, 200)
Are you using Nuxt?
Describe the bug
axios.js
main.js
app.vue
Got error
I know it can move into
axios.interceptors.request
inner, butuseUserStore(pinia)
can be work, whypinia-plugin-persistedstate
cannot. I think it maybe a bug.And I just reproduced the problem using Axios. In fact, in my project, there are many places where the store is created before Pinia. All of them use the way of
useUserStore(pinia)
. If modifications are to be made, this change will be very large.Reproduction
https://stackblitz.com/edit/vitejs-vite-tgnzng?file=src%2Faxios.js
System Info
Used Package Manager
npm
Validations