Nuxt · NUXT0029

Avoid browser globals in universal code

Flags browser global in universal code in Nuxt hydration code before it leaks into runtime behavior.
NUXT0029vite-doctor/nuxthydrationerrorSuggestion

Run this rule

pnpm nuxt doctor --rules nuxt/hydration/no-browser-global-in-universal-code

Why it matters

Server-rendered markup must match the first client render. Browser-only state, time, randomness, or hash-sensitive URLs can create hydration mismatches.

Remove browser global in universal code, or move it to the Nuxt runtime/API that owns that behavior.

Example

Avoid browser globals in universal render

Before

<script setup lang="ts">
const width = window.innerWidth
</script>

<template>{{ width }}</template>

After

<script setup lang="ts">
const width = ref<number>()
onMounted(() => { width.value = window.innerWidth })
</script>

<template>{{ width }}</template>
Copyright © 2026