load pinia persistence only when on client side

This commit is contained in:
Ulf Gebhardt 2023-11-23 05:39:57 +01:00
parent 89fa3f2b29
commit 8036f50bf3
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 12 additions and 4 deletions

View File

@ -19,7 +19,7 @@ async function render(pageContext: PageContextServer) {
throw new Error('My render() hook expects pageContext.Page to be defined')
}
const app = createApp(Page, pageProps, pageContext)
const app = createApp(Page, pageProps, pageContext, false)
const appHtml = await renderToString(app)

View File

@ -1,3 +1,4 @@
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createSSRApp, defineComponent, h } from 'vue'
import PageShell from '#components/PageShell.vue'
@ -10,7 +11,12 @@ import { PageProps } from '#types/PageProps'
import type { PageContext } from '#types/PageContext'
function createApp(Page: Page, pageProps: PageProps | undefined, pageContext: PageContext) {
function createApp(
Page: Page,
pageProps: PageProps | undefined,
pageContext: PageContext,
isClient = true,
) {
const PageWithLayout = defineComponent({
render() {
return h(
@ -25,6 +31,10 @@ function createApp(Page: Page, pageProps: PageProps | undefined, pageContext: Pa
},
})
if(isClient){
pinia.use(piniaPluginPersistedstate)
}
const app = createSSRApp(PageWithLayout)
app.use(pinia)
app.use(i18n)

View File

@ -1,6 +1,4 @@
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
export default pinia