Skip to content

Commit

Permalink
fix hydration error
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Mar 21, 2023
1 parent e711304 commit 17789cc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/client/theme-default/components/VPDocFooterLastUpdated.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed, watchEffect } from 'vue'
import { ref, computed, watchEffect, onMounted } from 'vue'
import { useData } from '../composables/data'
const { theme, page, lang } = useData()
Expand All @@ -8,8 +8,12 @@ const date = computed(() => new Date(page.value.lastUpdated!))
const isoDatetime = computed(() => date.value.toISOString())
const datetime = ref('')
watchEffect(() => {
datetime.value = date.value.toLocaleString(lang.value)
// set time on mounted hook to avoid hydration mismatch due to
// potential differences in timezones of the server and clients
onMounted(() => {
watchEffect(() => {
datetime.value = date.value.toLocaleString(lang.value)
})
})
</script>

Expand Down

0 comments on commit 17789cc

Please sign in to comment.