]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: remove reference to ViteSSR (#2083)
authorSimon <simon.toivo@gmail.com>
Wed, 7 Jun 2023 09:54:21 +0000 (11:54 +0200)
committerGitHub <noreply@github.com>
Wed, 7 Jun 2023 09:54:21 +0000 (11:54 +0200)
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
packages/docs/ssr/index.md

index a450522e1c078a7fb84d9dca332728eb2a6d186d..7cc389ff1d31ca2a2fd97018428ce7df07d1f5a7 100644 (file)
@@ -16,7 +16,7 @@ const main = useMainStore()
 
 ## Using the store outside of `setup()`
 
-If you need to use the store somewhere else, you need to pass the `pinia` instance [that was passed to the app](#install-the-plugin) to the `useStore()` function call:
+If you need to use the store somewhere else, you need to pass the `pinia` instance [that was passed to the app](../getting-started.md#installation) to the `useStore()` function call:
 
 ```js
 const pinia = createPinia()
@@ -78,42 +78,21 @@ 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. For example, with [vite-ssr](https://github.com/frandiox/vite-ssr) you can use the [`transformState` option](https://github.com/frandiox/vite-ssr#state-serialization) and `@nuxt/devalue`:
+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**.
 
-```js
-import devalue from '@nuxt/devalue'
-
-export default viteSSR(
-  App,
-  {
-    routes,
-    transformState(state) {
-      return import.meta.env.SSR ? devalue(state) : state
-    },
-  },
-  ({ initialState }) => {
-    // ...
-    if (import.meta.env.SSR) {
-      // this will be stringified and set to window.__INITIAL_STATE__
-      initialState.pinia = pinia.state.value
-    } else {
-      // on the client side, we restore the state
-      pinia.state.value = initialState.pinia
-    }
-  }
-)
-```
+If you are not using Nuxt you will need to handle the serialization and hydration of the state yourself. Here are some examples:
 
-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**.
+- [Vitesse template](https://github.com/antfu/vitesse/blob/main/src/modules/pinia.ts)
+- [vite-plugin-ssr](https://vite-plugin-ssr.com/pinia)
 
-Adapt this strategy to your environment. Make sure to hydrate pinia's state before calling any `useStore()` function on client side. For example, if we serialize the state into a `<script>` tag to make it accessible globally on client side through `window.__pinia`, we can write this:
+Adapt this strategy to your environment. **Make sure to hydrate pinia's state before calling any `useStore()` function** on client side. For example, if we serialize the state into a `<script>` tag to make it accessible globally on client side through `window.__pinia`, we can write this:
 
-```js
+```ts
 const pinia = createPinia()
 const app = createApp(App)
 app.use(pinia)
 
-// must be set by the user
+// `isClient` depends on the environment, e.g. on Nuxt it's `process.client`
 if (isClient) {
   pinia.state.value = JSON.parse(window.__pinia)
 }