Index of every page on this site: llms.txt
Hooks

script:updated Hook

The script:updated hook is emitted when a useScript() instance changes to loading, loaded, error, or removed. A new script starts in awaitingLoad, but creating it does not emit this hook until its status changes.

This hook also drives useScript()'s internal load promise and callbacks. Application code should normally use onLoaded(), onError(), load(), and remove() on the returned script instance instead.

Hook Signature

export interface Hook {
  'script:updated': (ctx: {
    script: ScriptInstance<any>
  }) => void | Promise<void>
}

Script Status

type UseScriptStatus =
  | 'awaitingLoad'
  | 'loading'
  | 'loaded'
  | 'error'
  | 'removed'

ScriptInstance exposes id, status, instance, proxy, signal, entry, load(), warmup(), remove(), setupTriggerHandler(), onLoaded(), and onError(). The status is read-only in the public type. Retry counters, fallback sources, loading timestamps, and an error property are not part of this API.

Usage Example

import { defineHeadPlugin } from '@unhead/vue/plugins'

export const scriptStatusPlugin = defineHeadPlugin({
  key: 'script-status',
  hooks: {
    'script:updated': ({ script }) => {
      console.log(`Script ${script.id}: ${script.status}`)
    }
  }
})

Hook promises are not used to delay script loading or status transitions.

Did this page help you?