Nuxt & Universal SSR (50 Qs)•Part 1: Nuxt 3 Fundamentals (Junior / Entry-Level)
What is `<ClientOnly>` and why is it used?
junior LevelCode ExampleCLIVue & Nuxt
In Simple Words:
Certain UI components rely strictly on browser-only Web APIs (window, localStorage, document, canvas, or third-party charting libraries like Chart.js or Leaflet). If executed on the Node.js server during SSR, they crash with ReferenceError: window is not defined or trigger a client-side hydration mismatch.
Wrapping these elements with <ClientOnly> tells Nuxt to skip rendering them on the server and render a placeholder until the client mounts.
vue
<template>
<div>
<h1>Analytics Dashboard</h1>
<ClientOnly>
<!-- Only mounts and renders inside browser -->
<BrowserGeoMap :coordinates="coords" />
<template #fallback>
<div class="skeleton-loader">Loading interactive map...</div>
</template>
</ClientOnly>
</div>
</template>