File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
packages/nuxt/src/runtime Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 11import { createPinia , setActivePinia } from 'pinia'
22import type { Pinia } from 'pinia'
3- import { defineNuxtPlugin , type Plugin } from '#app'
4- import { toRaw } from 'vue'
3+ import { defineNuxtPlugin , useNuxtApp , type Plugin } from '#app'
54
65const plugin : Plugin < { pinia : Pinia } > = defineNuxtPlugin ( {
76 name : 'pinia' ,
@@ -10,9 +9,7 @@ const plugin: Plugin<{ pinia: Pinia }> = defineNuxtPlugin({
109 nuxtApp . vueApp . use ( pinia )
1110 setActivePinia ( pinia )
1211
13- if ( import . meta. server ) {
14- nuxtApp . payload . pinia = toRaw ( pinia . state . value )
15- } else if ( nuxtApp . payload && nuxtApp . payload . pinia ) {
12+ if ( nuxtApp . payload && nuxtApp . payload . pinia ) {
1613 pinia . state . value = nuxtApp . payload . pinia as any
1714 }
1815
@@ -23,6 +20,13 @@ const plugin: Plugin<{ pinia: Pinia }> = defineNuxtPlugin({
2320 } ,
2421 }
2522 } ,
23+ hooks : {
24+ 'app:rendered' ( ) {
25+ const nuxtApp = useNuxtApp ( )
26+ nuxtApp . payload . pinia = ( nuxtApp . $pinia as Pinia ) . state . value
27+ setActivePinia ( undefined )
28+ } ,
29+ } ,
2630} )
2731
2832export default plugin
You can’t perform that action at this time.
0 commit comments