From: Eduardo San Martin Morote Date: Sun, 27 Oct 2024 19:10:48 +0000 (+0100) Subject: docs: recommend plain devalue X-Git-Tag: @pinia/nuxt@0.6.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5dbaee1cc09e31cb66b198791bb84604dd4aa33;p=thirdparty%2Fvuejs%2Fpinia.git docs: recommend plain devalue --- diff --git a/packages/docs/ssr/index.md b/packages/docs/ssr/index.md index 43f4e777..1d1001c9 100644 --- a/packages/docs/ssr/index.md +++ b/packages/docs/ssr/index.md @@ -63,10 +63,10 @@ onServerPrefetch(async () => { ## State hydration -To hydrate the initial state, you need to make sure the rootState is included somewhere in the HTML for Pinia to pick it up later on. Depending on what you are using for SSR, **you should escape the state for security reasons**. We recommend using [@nuxt/devalue](https://github.com/nuxt-contrib/devalue) which is the one used by Nuxt.js: +To hydrate the initial state, you need to make sure the rootState is included somewhere in the HTML for Pinia to pick it up later on. Depending on what you are using for SSR, **you should escape the state for security reasons**. We recommend using [devalue](https://github.com/Rich-Harris/devalue) which is the one used by Nuxt.js: ```js -import devalue from '@nuxt/devalue' +import devalue from 'devalue' import { createPinia } from 'pinia' // retrieve the rootState server side const pinia = createPinia() @@ -83,7 +83,7 @@ app.use(pinia) devalue(pinia.state.value) ``` -Depending on what you are using for SSR, you will set an _initial state_ variable that will be serialized in the HTML. You should also protect yourself from XSS attacks. You can use [other alternatives](https://github.com/nuxt-contrib/devalue#see-also) to `@nuxt/devalue` depending on what you need, e.g. if you can serialize and parse your state with `JSON.stringify()`/`JSON.parse()`, **you could improve your performance by a lot**. +Depending on what you are using for SSR, you will set an _initial state_ variable that will be serialized in the HTML. You should also protect yourself from XSS attacks. You can use [other alternatives](https://github.com/Rich-Harris/devalue#see-also) to `devalue` depending on what you need, e.g. if you can serialize and parse your state with `JSON.stringify()`/`JSON.parse()`, **you could improve your performance by a lot**. If you are not using Nuxt you will need to handle the serialization and hydration of the state yourself. Here are some examples: