Vue · VUE0042
Do not initialize SSR-rendered state from a browser read in setup
Flags ref(), reactive() and computed() state whose initial value comes from a browser read during setup of server-rendered Vue code, directly or through a helper.
vue/ssr/no-setup-state-from-browser-readsrc/rule-packs/vue/rules/vue/no-setup-state-from-browser-read.ts Upstream docs Run this rule
pnpm vite-doctor . --framework vue --rules vue/ssr/no-setup-state-from-browser-read
Why it matters
The server cannot read localStorage, navigator.onLine or the viewport, so it renders the fallback, while the first client render starts from the browser value. Vue then logs a hydration mismatch and patches or rebuilds the subtree. A typeof window or import.meta.client guard prevents the server crash but is exactly what makes the two renders differ. Doctor follows the read through local variables and through functions in the same file or a relative import.
Recommended fix
Initialize the state to a value the server can compute too, such as the prop default, and apply the browser value in onMounted(). In a Nuxt app, keep state the server must render in useState() or useCookie(), or render the subtree in <ClientOnly>.
Useful links
Example
Apply stored layout after mount
Before
setup(props) {
const stored = readLayout(props.storageKey) // reads localStorage when it exists
const width = ref(stored.width ?? props.defaultWidth)
}
After
setup(props) {
const width = ref(props.defaultWidth)
onMounted(() => { width.value = readLayout(props.storageKey).width ?? width.value })
}