Nuxt · NUXT0029
Avoid browser globals in universal code
Flags browser global in universal code in Nuxt hydration code before it leaks into runtime behavior.
nuxt/hydration/no-browser-global-in-universal-codesrc/rule-packs/nuxt/rules/nuxt/no-browser-global-in-universal-code.ts Upstream docs 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.
Recommended fix
Remove browser global in universal code, or move it to the Nuxt runtime/API that owns that behavior.
Useful links
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>