useSkewProtection() · Nuxt Skew Protection · Nuxt SEO

[NuxtSEO Pro](https://nuxtseo.com/ "Home")

- [Modules](https://nuxtseo.com/docs/nuxt-seo/getting-started/introduction)
- [Tools](https://nuxtseo.com/tools)
- [Pro](https://nuxtseo.com/pro)
- [Learn SEO](https://nuxtseo.com/learn-seo/nuxt) [Releases](https://nuxtseo.com/releases)

[Sign In](https://nuxtseo.com/auth/github)

[Nuxt SEO on GitHub](https://github.com/harlan-zw/nuxt-seo)

[User Guides](https://nuxtseo.com/docs/skew-protection/getting-started/introduction)

[API](https://nuxtseo.com/docs/skew-protection/api/use-skew-protection)

[Releases](https://nuxtseo.com/docs/skew-protection/releases/v1)

Skew Protection

- [Switch to Skew Protection](https://nuxtseo.com/docs/skew-protection/getting-started/introduction)
- [Switch to Nuxt SEO](https://nuxtseo.com/docs/nuxt-seo/getting-started/introduction)
- [Switch to Robots](https://nuxtseo.com/docs/robots/getting-started/introduction)
- [Switch to Sitemap](https://nuxtseo.com/docs/sitemap/getting-started/introduction)
- [Switch to OG Image](https://nuxtseo.com/docs/og-image/getting-started/introduction)
- [Switch to Schema.org](https://nuxtseo.com/docs/schema-org/getting-started/introduction)
- [Switch to Link Checker](https://nuxtseo.com/docs/link-checker/getting-started/introduction)
- [Switch to SEO Utils](https://nuxtseo.com/docs/seo-utils/getting-started/introduction)
- [Switch to Site Config](https://nuxtseo.com/docs/site-config/getting-started/introduction)
- [Switch to AI Ready](https://nuxtseo.com/docs/ai-ready/getting-started/introduction)

Search…```k`` /`

v1.1.1

- [Discord Support](https://discord.com/invite/275MBUBvgP)

### Nuxt API

- [`useSkewProtection()`](https://nuxtseo.com/docs/skew-protection/api/use-skew-protection)
- [`useActiveConnections()`](https://nuxtseo.com/docs/skew-protection/api/use-active-connections)
- [`<SkewNotification />`](https://nuxtseo.com/docs/skew-protection/api/skew-notification)
- [nuxt.config.ts](https://nuxtseo.com/docs/skew-protection/api/config)
- [Nuxt Hooks](https://nuxtseo.com/docs/skew-protection/api/nuxt-hooks)

### Nitro API

- [`isClientOutdated()`](https://nuxtseo.com/docs/skew-protection/nitro-api/is-client-outdated)
- [Nitro Hooks](https://nuxtseo.com/docs/skew-protection/nitro-api/nitro-hooks)

Nuxt API

# useSkewProtection()

[Copy for LLMs](https://nuxtseo.com/docs/skew-protection/api/use-skew-protection.md)

The main composable for interacting with Nuxt Skew Protection.

## [Usage](#usage)

```
const skew = useSkewProtection()
```

## [Options](#options)

### [`lazy`](#lazy)

- Type: `boolean`
- Default: `false`

When `false` (default), the composable establishes the connection automatically when called in a mounted component. When `true`, you must call `connect()` manually.

```
// Auto-connect on mount (default)
const skew = useSkewProtection()

// Manual connection control
const skew = useSkewProtection({ lazy: true })
skew.connect() // Connect when ready
```

## [Returns](#returns)

### [`manifest`](#manifest)

- Type: `Ref<NuxtAppManifestMeta | null>`

The current build manifest from `builds/latest.json`.

```
const { manifest } = useSkewProtection()

console.log(manifest.value?.id) // Current buildId
console.log(manifest.value?.timestamp) // Build timestamp
```

### [`clientVersion`](#clientversion)

- Type: `string`

The user's current version (from cookie or buildId).

```
const { clientVersion } = useSkewProtection()

console.log(clientVersion) // "abc123"
```

### [`isAppOutdated`](#isappoutdated)

- Type: `ComputedRef<boolean>`

Whether the user's version is outdated.

```
const { isAppOutdated } = useSkewProtection()

if (isAppOutdated.value) {
  console.log('User is on an old version')
}
```

### [`isConnected`](#isconnected)

- Type: `ComputedRef<boolean>`

Whether the SSE/WebSocket connection is currently active.

```
const { isConnected } = useSkewProtection()

if (isConnected.value) {
  console.log('Connected to update stream')
}
```

### [`connect()`](#connect)

- Type: `() => void`

Manually establish the connection. Only needed when using `lazy: true`.

```
const skew = useSkewProtection({ lazy: true })

// Connect when user clicks a button
function handleConnect() {
  skew.connect()
}
```

### [`disconnect()`](#disconnect)

- Type: `() => void`

Manually close the connection. Useful for cleanup or pausing updates.

```
const { disconnect } = useSkewProtection()

// Disconnect when leaving a section
onBeforeRouteLeave(() => {
  disconnect()
})
```

### [`checkForUpdates()`](#checkforupdates)

- Type: `() => Promise<void>`

Manually trigger an update check.

```
const { checkForUpdates } = useSkewProtection()

// Check for updates
await checkForUpdates()
```

### [`onAppOutdated()`](#onappoutdated)

- Type: `(callback: (manifest: NuxtAppManifestMeta | null) => void) => void`

Triggers when it detects a new version, regardless of whether it affects the current session. Uses Nuxt's built-in `app:manifest:update` hook.

**Use case:** Make next page load a hard navigation (forces HTML reload).

```
const { onAppOutdated } = useSkewProtection()
onAppOutdated((manifest) => {
  console.log('New version available:', manifest?.id)
  // Show passive "Update available" badge
})
```

### [`onCurrentChunksOutdated()`](#oncurrentchunksoutdated)

- Type: `(callback: (payload: ChunksOutdatedPayload) => void) => void`

Triggers **only** when the user's loaded JavaScript modules have been changed in a new deployment.

Consider the case of a user on a blog post when you deploy a new version that only changes the homepage. The user's session is unaffected and they can continue browsing without interruption. In this case, `onCurrentChunksOutdated` will not trigger.

Under the hood this tracks modules using a service worker.

```
const { onCurrentChunksOutdated } = useSkewProtection()

onCurrentChunksOutdated((payload) => {
  console.log('Deleted chunks:', payload.deletedChunks)
  console.log('Invalidated modules:', payload.invalidatedModules)
  console.log('Passed releases:', payload.passedReleases)

  // Show notification
  alert('Please reload to get the latest version')
})
```

## [Type Definitions](#type-definitions)

```
interface NuxtAppManifestMeta {
  id: string
  timestamp: number
  skewProtection?: {
    current: string
    versions: Record<string, VersionInfo>
  }
}

interface VersionInfo {
  timestamp: string
  expires: string
  assets: string[]
  deletedChunks?: string[]
}

interface ChunksOutdatedPayload {
  deletedChunks: string[]
  invalidatedModules: string[]
  passedReleases: string[]
}
```

## [Examples](#examples)

### [Custom Invalidation Handler](#custom-invalidation-handler)

```
const { onCurrentChunksOutdated } = useSkewProtection()

onCurrentChunksOutdated(({ invalidatedModules, passedReleases }) => {
  // Track in analytics
  analytics.track('chunks_outdated', {
    count: invalidatedModules.length,
    modules: invalidatedModules,
    releases: passedReleases
  })

  // Show custom UI
  showUpdateDialog({
    title: 'Update Required',
    message: \`${invalidatedModules.length} modules need updating (${passedReleases.length} releases passed)\`
  })
})
```

### [Version Information Display](#version-information-display)

```
<script setup lang="ts">
const { clientVersion, manifest } = useSkewProtection()

const buildDate = computed(() => {
  if (!manifest.value?.timestamp)
    return null
  return new Date(manifest.value.timestamp).toLocaleString()
})
</script>

<template>
  <div class="version-info">
    <p>Your version: {{ clientVersion }}</p>
    <p>Latest version: {{ manifest?.id }}</p>
    <p>Build date: {{ buildDate }}</p>
  </div>
</template>
```

### [Programmatic Update Check](#programmatic-update-check)

Note: Only relevant if you're using `polling`.

```
const { checkForUpdates, isAppOutdated } = useSkewProtection()

async function handleUserAction() {
  // Check for updates before critical action
  await checkForUpdates()

  if (isAppOutdated.value) {
    const shouldReload = confirm('A new version is available. Reload now?')
    if (shouldReload) {
      window.location.reload()
    }
  }
  else {
    // Proceed with action
    await performCriticalAction()
  }
}
```

[Edit this page](https://github.com/nuxt-seo-pro/nuxt-skew-protection/edit/main/docs/content/3.api/1.use-skew-protection.md)

[Markdown For LLMs](https://nuxtseo.com/docs/skew-protection/api/use-skew-protection.md)

Did this page help you?

[Nuxt Hooks Learn how to use Nuxt hooks to respond to skew protection events.](https://nuxtseo.com/docs/skew-protection/api/nuxt-hooks) [<SkewNotification>Headless component for displaying update notifications.](https://nuxtseo.com/docs/skew-protection/api/skew-notification)

On this page

- [Usage](#usage)
- [Options](#options)
- [Returns](#returns)
- [Type Definitions](#type-definitions)
- [Examples](#examples)

[GitHub](https://github.com/harlan-zw/nuxt-seo) [ Discord](https://discord.com/invite/275MBUBvgP)

### [NuxtSEO](https://nuxtseo.com/ "Home")

- [Getting Started](https://nuxtseo.com/docs/nuxt-seo/getting-started/introduction)
- [MCP](https://nuxtseo.com/docs/nuxt-seo/guides/mcp)

Modules

- [Robots](https://nuxtseo.com/docs/robots/getting-started/introduction)
- [Sitemap](https://nuxtseo.com/docs/sitemap/getting-started/introduction)
- [OG Image](https://nuxtseo.com/docs/og-image/getting-started/introduction)
- [Schema.org](https://nuxtseo.com/docs/schema-org/getting-started/introduction)
- [Link Checker](https://nuxtseo.com/docs/link-checker/getting-started/introduction)
- [SEO Utils](https://nuxtseo.com/docs/seo-utils/getting-started/introduction)
- [Site Config](https://nuxtseo.com/docs/site-config/getting-started/introduction)
- [Skew Protection](https://nuxtseo.com/docs/skew-protection/getting-started/introduction)
- [AI Ready](https://nuxtseo.com/docs/ai-ready/getting-started/introduction)

### [NuxtSEO Pro](https://nuxtseo.com/pro "Home")

- [Getting Started](https://nuxtseo.com/pro)
- [Dashboard](https://nuxtseo.com/pro/dashboard)
- [Pro MCP](https://nuxtseo.com/docs/nuxt-seo-pro/mcp/installation)

### [Learn SEO](https://nuxtseo.com/learn-seo "Learn SEO")

Nuxt

- [Mastering Meta](https://nuxtseo.com/learn-seo/nuxt/mastering-meta)
- [Controlling Crawlers](https://nuxtseo.com/learn-seo/nuxt/controlling-crawlers)
- [Launch & Listen](https://nuxtseo.com/learn-seo/nuxt/launch-and-listen)
- [Routes & Rendering](https://nuxtseo.com/learn-seo/nuxt/routes-and-rendering)
- [Staying Secure](https://nuxtseo.com/learn-seo/nuxt/routes-and-rendering/security)

Vue

- [Vue SEO Guide](https://nuxtseo.com/learn-seo/vue)
- [Mastering Meta](https://nuxtseo.com/learn-seo/vue/mastering-meta)
- [Controlling Crawlers](https://nuxtseo.com/learn-seo/vue/controlling-crawlers)
- [SPA SEO](https://nuxtseo.com/learn-seo/vue/spa)
- [SSR Frameworks](https://nuxtseo.com/learn-seo/vue/ssr-frameworks)
- [SEO Checklist](https://nuxtseo.com/learn-seo/checklist)
- [Pre-Launch Warmup](https://nuxtseo.com/learn-seo/pre-launch-warmup)
- [Backlinks & Authority](https://nuxtseo.com/learn-seo/backlinks)

### [Tools](https://nuxtseo.com/tools "SEO Tools")

- [Social Share Debugger](https://nuxtseo.com/tools/social-share-debugger)
- [Robots.txt Generator](https://nuxtseo.com/tools/robots-txt-generator)
- [Meta Tag Checker](https://nuxtseo.com/tools/meta-tag-checker)
- [HTML to Markdown](https://nuxtseo.com/tools/html-to-markdown)
- [XML Sitemap Validator](https://nuxtseo.com/tools/xml-sitemap-validator)
- [Schema.org Validator](https://nuxtseo.com/tools/schema-validator)
- [Keyword Idea Generator](https://nuxtseo.com/tools/keyword-generator)
- [Keyword Research](https://nuxtseo.com/tools/keyword-research)
- [SERP Analyzer](https://nuxtseo.com/tools/serp-analyzer)
- [Domain Rankings](https://nuxtseo.com/tools/domain-rankings)

Copyright © 2023-2026 Harlan Wilton - [MIT License](https://github.com/harlan-zw/nuxt-seo/blob/main/license) · [mdream](https://mdream.dev)