Vite · SSR safety

VITE0018Avoid browser globals in Vite SSR entries

Flags browser global in SSR entry in Vite SSR code before it leaks into runtime behavior.

Why it happens

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

Fix

Remove browser global in SSR entry, or move it to the Vite runtime/API that owns that behavior.

Example

Avoid browser globals in SSR entry

Before

export function render() {
  return window.location.href
}

After

export function render(url: string) {
  return url
}

Verify the fix

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

pnpm vite-doctor . --framework vite --rules vite/ssr/no-browser-global-in-ssr-entry
Copyright © 2026