Avoid random, current-time, or locale-dependent SSR render values
vue/ssr/no-random-or-local-time-rendersrc/rule-packs/vue/rules/vue/no-random-or-local-time-render.ts Upstream docs Run this rule
pnpm vite-doctor . --framework vue --rules vue/ssr/no-random-or-local-time-render
Why it matters
Math.random(), Date.now() and new Date() return a different value on the server and in the browser, and toLocaleString(), toLocaleDateString(), Intl.DateTimeFormat and Intl.NumberFormat without an explicit locale or timeZone format with the settings of the process that renders. The first client render then differs from the server HTML and Vue logs a hydration mismatch. Doctor checks SFC scripts, and in .ts and .tsx files the values inside render functions, h() arguments and JSX, including values that a helper from the same file or a relative import computes.
Recommended fix
Render a value the server and the client agree on, such as a UTC date formatted with an explicit locale and timeZone, and switch to the local or relative value in onMounted(). Use useId() for ids, or isolate the node with data-allow-mismatch.
Useful links
Example
Render a stable date, then the local one after mount
Before
return () => h("time", { title: new Date(props.at).toLocaleString() }, timeAgo(props.at))
After
const mounted = ref(false)
onMounted(() => { mounted.value = true })
return () => h("time", { title: new Date(props.at).toISOString() }, mounted.value ? timeAgo(props.at) : new Date(props.at).toISOString().slice(0, 10))