Skip to content

Commit 1c1677f

Browse files
committed
docs: add wip ssr
1 parent ee6db04 commit 1c1677f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/guide/ssr.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Server Side Rendering
2+
3+
When doing SSR (Server Side Rendering) you want to wait for the data on the server to serialize it and retrieve it on the client side where it will displayed
4+
5+
## Vue 3 + Suspense
6+
7+
By serializing the data on the server (using a store like [Pinia](https://pinia.vuejs.org) for example) and `await`ing the returned `promise` of `useDocument()` you can ensure your data is loaded when rendering the page on the server and hydrating on the client.
8+
9+
```vue
10+
<script lang="ts" setup>
11+
const { data: userList, promise } = useCollection(collection(db, 'users'))
12+
13+
await promise.value
14+
</script>
15+
```
16+
17+
:::tip
18+
Make sure your component is the descendant of [`<Suspense>`](https://vuejs.org/guide/built-ins/suspense.html) in order to use `await` within `<script setup>`.
19+
:::
20+
21+
## Vue Router Data Loaders
22+
23+
Get the data once only on server
24+
25+
```vue
26+
<script lang="ts">
27+
export const useUserList = defineLoader(async () => {
28+
const { data: users, promise } = useCollection(collection(db, 'users'), { once: true })
29+
// or
30+
// const users = await useCollectionOnce(collection(db, 'users'))
31+
return users
32+
})
33+
</script>
34+
35+
<script setup lang="ts">
36+
const { data: users } = useUserList()
37+
</script>
38+
```

0 commit comments

Comments
 (0)