Vue · SSR safety

VUE0012Avoid random, current-time, or locale-dependent SSR render values

Flags random numbers, the current time, and default-locale or local-time-zone formatting in server-rendered Vue output.

Why it happens

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.

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.

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))

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework vue --rules vue/ssr/no-random-or-local-time-render
Copyright © 2026