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 1
1
import { createPinia , setActivePinia } from 'pinia'
2
2
import type { Pinia } from 'pinia'
3
- import { defineNuxtPlugin , type Plugin } from '#app'
4
- import { toRaw } from 'vue'
3
+ import { defineNuxtPlugin , useNuxtApp , type Plugin } from '#app'
5
4
6
5
const plugin : Plugin < { pinia : Pinia } > = defineNuxtPlugin ( {
7
6
name : 'pinia' ,
@@ -10,9 +9,7 @@ const plugin: Plugin<{ pinia: Pinia }> = defineNuxtPlugin({
10
9
nuxtApp . vueApp . use ( pinia )
11
10
setActivePinia ( pinia )
12
11
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 ) {
16
13
pinia . state . value = nuxtApp . payload . pinia as any
17
14
}
18
15
@@ -23,6 +20,13 @@ const plugin: Plugin<{ pinia: Pinia }> = defineNuxtPlugin({
23
20
} ,
24
21
}
25
22
} ,
23
+ hooks : {
24
+ 'app:rendered' ( ) {
25
+ const nuxtApp = useNuxtApp ( )
26
+ nuxtApp . payload . pinia = ( nuxtApp . $pinia as Pinia ) . state . value
27
+ setActivePinia ( undefined )
28
+ } ,
29
+ } ,
26
30
} )
27
31
28
32
export default plugin
You can’t perform that action at this time.
0 commit comments