pinia-plugin-persistedstate icon indicating copy to clipboard operation
pinia-plugin-persistedstate copied to clipboard

feat✨: allow to change and persist cookie before nuxt init

Open MZ-Dlovely opened this issue 2 years ago • 9 comments

Description

when opening a page on bowser, nuxt will be initialized and generate a html as response. if you are doing some thing like useStore and change store with nuxt's plugin, it will not persist state because there is no nuxt instance.

so, I make a new nitro plugin to make sure the initialize connection can obtain data of cookies from client side, and set cookies after pinia store is changed.

but the problem that our plugin is not able to get nuxt instance is still unresolved, so I provided a method to tell the plugin what to pass.

Linked Issues

#221

Additional context

maybe we need to test how it work after many revision

MZ-Dlovely avatar Aug 15 '23 06:08 MZ-Dlovely

will have a look when i get some time 👍

prazdevs avatar Aug 17 '23 18:08 prazdevs

sorry been really overloaded with work atm, havent found time yet to look into it 😓

prazdevs avatar Aug 31 '23 13:08 prazdevs

I checked a bit and played with it. I like where this is going and it makes working with stores in middleware possible, however, I'm not sure this is the final API we want, especially the persistCookie . Maybe we can find a way to reuse the store config ?

prazdevs avatar Sep 04 '23 21:09 prazdevs

I checked a bit and played with it. I like where this is going and it makes working with stores in middleware possible, however, I'm not sure this is the final API we want, especially the persistCookie . Maybe we can find a way to reuse the store config ?

I try to do the same thing inset the plugin like persistCookie doing, but it's not possible to obtain event because the env of plugin is lay in outside of nuxt(I cannot understand).so I have to extract it for users to use. maybe someone can come up with a better plan? :P

MZ-Dlovely avatar Sep 05 '23 09:09 MZ-Dlovely

Ok so maybe we could just copy/paste the pick method to the nuxt plugin to avoid touching the base plugin at all while we work on the Nuxt thing. Later if we ever export it, we may want to strip it from types as it's an internal thing as well 🤔

Then we merge and move forward to see how we can improve it. But at least people can try playing around with it. Maybe tag is as experimental or sth

prazdevs avatar Sep 06 '23 22:09 prazdevs

cannot agree more

maybe, we can use the get and set of lodash-es instead of pick and others? then each performs its own functions.

MZ-Dlovely avatar Sep 07 '23 02:09 MZ-Dlovely

Ig it's fine using lodash-es in the Nuxt plugin, we'll see later what we can do. This issue has to be adressed so let's try things! I let you update the PR with whatever is needed from lodash to avoid changing the base plugin. So modifications only happen in the Nuxt package. :)

prazdevs avatar Sep 07 '23 10:09 prazdevs

I'm sorry I have no enough time to do it last week. maybe there's time in a few days.

MZ-Dlovely avatar Sep 14 '23 02:09 MZ-Dlovely

nw take your time ^_^ lodash are working on a v5 with native typescript, usm exports so could be a good start to see what we can do with it when they're done too. if it's really worth it we can always even put it in the main plugin. 👍

prazdevs avatar Sep 17 '23 01:09 prazdevs