Hooks
ssr:render Hook
On this page
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
| Name | Type | Description |
|---|---|---|
ctx.tags | HeadTag[] | Sanitized tags selected for this render |
ctx.options | RenderSSRHeadOptions | Fresh 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?
On this page