Skip to content

Commit 29aa2eb

Browse files
committed
copilot
1 parent eacad2e commit 29aa2eb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

examples/vue-pinia/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ This example demonstrates:
55
- Client-side state persistence using `pinia-plugin-persistedstate` (About page: counter persists across page reloads)
66
- Using `onCreatePinia` hook to register Pinia plugins
77
- Todo list with SSR data fetching and store population
8+
- Client-only rendering for persisted stores to avoid hydration mismatches
89

910
> [!NOTE]
10-
> The home page uses a **non-persisted** store to demonstrate SSR without hydration issues. The about page uses a **persisted** store to demonstrate localStorage persistence.
11+
> The home page uses a **non-persisted** store to demonstrate SSR without hydration issues. The about page uses a **persisted** store with **client-only rendering** (`v-if="mounted"`) to avoid hydration mismatches between server (no localStorage) and client (has localStorage).
1112
1213
> [!NOTE]
1314
> For more examples, see [Bati](https://batijs.dev) which generates `vike-vue` apps.

examples/vue-pinia/pages/about/+Page.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
<h1>About</h1>
33
<p>Example of using Pinia with state persistence.</p>
44
<p><strong>This counter persists across page reloads (stored in localStorage)</strong></p>
5-
<PersistedCounter id="counter-3" />
5+
<PersistedCounter v-if="mounted" id="counter-3" />
6+
<div v-else>Loading...</div>
67
</template>
78

89
<script lang="ts" setup>
10+
import { ref, onMounted } from 'vue'
911
import PersistedCounter from '../../components/PersistedCounter.vue'
12+
13+
const mounted = ref(false)
14+
onMounted(() => {
15+
mounted.value = true
16+
})
1017
</script>

0 commit comments

Comments
 (0)