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

dom:beforeRender Hook

The dom:beforeRender hook runs immediately before the client renderer resolves tags and patches the document. Set ctx.shouldRender to false to cancel that render.

Hook Signature

export interface Hook {
  'dom:beforeRender': (ctx: DomBeforeRenderCtx) => SyncHookResult
}

interface DomBeforeRenderCtx {
  shouldRender: boolean
  tags: HeadTag[]
}

The hook is synchronous. In the current renderer, ctx.tags is initialized to an empty array because tag resolution happens after this hook. Use a tags:* hook to inspect tags.

Canceling a render does not clear the head's dirty state. A later update or explicit head.render() call can try again.

Usage Example

import { defineHeadPlugin } from 'unhead/plugins'

export function pauseDomRendering(isPaused: () => boolean) {
  return defineHeadPlugin({
    key: 'pause-dom-rendering',
    hooks: {
      'dom:beforeRender': (ctx) => {
        if (isPaused())
          ctx.shouldRender = false
      }
    }
  })
}
Did this page help you?