vue-hydration-mismatch
A value that differs between the server and the browser, computed while the component is set up or rendered: Date.now(), new Date(), Math.random(), crypto.randomUUID(), performance.now().
Why: with server-side rendering, the server sends HTML, and the browser then renders the same component again and attaches to that HTML (hydration). It expects the same result. A time or a random id is different the second time, so Vue finds HTML that doesn't match what it rendered: it warns, and patches or rebuilds that part of the page, which flickers and can leave the wrong content. Guide: Vue.
Only reported when the app renders on a server: "safe-ts": { "vue": { "ssr": true } } in the nearest package.json that has a "safe-ts" field, or a project that depends on nuxt. (So the examples below aren't run by the documentation tests.)
❌ Rejected
vue
<script setup lang="ts">
const inputId = `email-${Math.random().toString(36).slice(2)}`;
const year = new Date().getFullYear();
</script>
<template>
<label :for="inputId">Email</label>
<input :id="inputId" />
<footer>© {{ year }}</footer>
</template>✅ Accepted
vue
<script setup lang="ts">
import { onMounted, shallowRef, useId } from "vue";
import type { Option } from "@evobug_com/safe-ts-std/result";
const inputId = useId();
// Unknown on the server: set in the browser, after hydration.
const year = shallowRef<Option<number>>(undefined);
onMounted(() => {
year.value = new Date().getFullYear();
});
</script>
<template>
<label :for="inputId">Email</label>
<input :id="inputId" />
<footer v-if="year !== undefined">© {{ year }}</footer>
</template>useId() (Vue 3.5) gives the same id on the server and in the browser. For values the browser must see exactly as the server computed them, pass them along with the HTML (useState in Nuxt).
What the rule can't see: other values that differ by machine, like a date formatted in the server's time zone or language (toLocaleString()), or anything read from the environment.