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

ssr:render Hook

The ssr:render hook runs after tags have been resolved and immediately before they are serialized into an SSRHeadPayload.

Hook Signature

export interface Hook {
  'ssr:render': (ctx: {
    tags: HeadTag[]
    options: RenderSSRHeadOptions
  }) => HookResult
}

Parameters

NameTypeDescription
ctx.tagsHeadTag[]Sanitized tags selected for this render
ctx.optionsRenderSSRHeadOptionsFresh copy of the renderer options for this render

RenderSSRHeadOptions includes omitLineBreaks, resolvedTags, and tagWeight. At this stage, resolvedTags and tagWeight have already been used to select and order ctx.tags; changing them has no effect on the current render. Changing omitLineBreaks affects serialization.

Although the hook type permits a promise, serialization starts immediately after the hook call. Keep this hook synchronous.

Usage Example

import { defineHeadPlugin } from 'unhead/plugins'

export const ssrReportPlugin = defineHeadPlugin({
  key: 'ssr-report',
  hooks: {
    'ssr:render': ({ tags }) => {
      console.log(`Serializing ${tags.length} head tags`)
    }
  }
})

Use MinifyPlugin instead of setting omitLineBreaks directly when you also want to minify inline JavaScript, CSS, or JSON.

Did this page help you?