Skip to content
// EFFECT DAYS 2026

Head unstable

The host-neutral part of a component's head: the title, title templates, and the fold that turns a tree of entries into one value.

Any component can contribute head entries through a pure head option, a function of its Model, props and queries. On every flush that changed a view, the runtime folds the entries of the placed tree, fallback content included, into one value with the root vocabulary's merge, and a mount that owns the document hands it to its host. A component on a host-neutral vocabulary may contribute only title and titleTemplate. The HTML vocabulary adds meta, link, JSON-LD and the <html> and <body> attributes in HtmlHead.

The fold

Each node's value is its own entries followed by its children's values, so a descendant overrides its ancestors. Children are taken in the order of their paths, never in document order, so moving a component in its parent's view can't change the head. The node's reduce entries then map that value in written order, and the root's result is final.

  • Titles. A titleTemplate applies to a title set by a descendant, never to its own instance's title, so the title passes through its ancestors' templates outward, nearest first.
  • Conflicts. Siblings that set one single slot, such as the title, to the same value pass it up once. When they set different values, neither wins: the slot is left unset until an ancestor's reduce sets it. A conflict no ancestor settles is reported as a Conflict naming every path that set the slot. The runtime sends it to Query.Problems.

Example A layout template and a page title

import { Head } from "effect/ui"
const head = Head.merge({
entries: [Head.titleTemplate((title) => `${title} ยท App`)],
children: [{
entries: [Head.titleTemplate((title) => `${title} ยท People`), Head.title("People")],
children: [{ entries: [Head.title("Ada")], children: [] }]
}]
})
head.title // => "Ada ยท People ยท App"
14 exports Since v4.2.0 Source

Combinators

merge

unstable
Since v4.2.0

Folds a host-neutral tree into its title, applying each node's reduce entries bottom up.

Details

Entries of other vocabularies are ignored, HtmlHead.reduce included. Siblings that pass different titles up leave the title unset, and are reported to onConflict unless a reduce above them sets it.

Signature

declare const merge: <E extends {
readonly _tag: string;
} = Entry>(tree: Tree<E>, options?: MergeOptions) => Head

Constructors

conflict

unstable
Since v4.2.0

Makes the Conflict for a slot that the components at paths set to different values.

Signature

declare function conflict(slot: string, paths: readonly Array<string>): Conflict

reduce

unstable
Since v4.2.0

Maps the folded head of the instance and everything its view placed. Only the title of f's result is used: every other field of the full value is kept, so under the HTML vocabulary the meta, links and <html> and <body> attributes stay as they were.

Details

A node's reduce entries run after its own entries and its children's values are merged, in written order wherever they sit among the other entries, each given the previous one's result. A reduce that throws fails its instance, as a throwing head does. A merge called directly reports it to the node's onError and gives the next reduce the value the thrower was given. Use HtmlHead.reduce to read or set the HTML fields.

Signature

declare function reduce(f: (below: Head) => Head): Reduce

Example Marking a preview

import { Head } from "effect/ui"
const preview = Head.reduce((below) => ({ title: `[preview] ${below.title}` }))
const head = Head.merge({
entries: [Head.titleTemplate((title) => `${title} ยท App`), preview],
children: [{ entries: [Head.title("Ada")], children: [] }]
})
head.title // => "[preview] Ada ยท App"

title

unstable
Since v4.2.0

Sets the title.

Signature

declare function title(text: string): Title
Since v4.2.0

Wraps the title a descendant sets, such as (title) => \${title} ยท App``.

Details

It never applies to a title set by its own instance. Templates chain outward: the nearest ancestor's applies first. When an instance has several, the last one counts.

Signature

declare function titleTemplate(apply: (title: string) => string): TitleTemplate

Models

Entry

type unstable
Since v4.2.0

A host-neutral head entry: a title, a title template or a reduce.

Signature

type Entry = Title | TitleTemplate | Reduce

MergeOptions

interface unstable
Since v4.2.0

Options of a merge: where it reports a Conflict.

Signature

interface MergeOptions {
readonly onConflict?: (conflict: Conflict) => void;
}

Reduce

interface unstable
Since v4.2.0

Maps the folded head of its node: its own entries merged with its children's values.

Signature

interface Reduce {
readonly _tag: "Reduce";
readonly apply: <H extends Head>(below: H) => Omit<H, "title"> & Head;
}

Title

interface unstable
Since v4.2.0

The title: the document's, a window's or a screen's, as the host gives it a meaning. The Router's navigation announcement reads it.

Signature

interface Title {
readonly _tag: "Title";
readonly text: string;
}

TitleTemplate

interface unstable
Since v4.2.0

Wraps the title set by a descendant.

Signature

interface TitleTemplate {
readonly _tag: "TitleTemplate";
readonly apply: (title: string) => string;
}

Tree

interface unstable
Since v4.2.0

A tree of head entries: each node's own entries and its children, in document order. The runtime builds one node per instance.

Details

path names the node in a Conflict, and orders it among its siblings. Siblings with entries in their subtree need distinct paths: a merge throws when two have none or share one, whatever their order. onError is called when one of the node's own title templates or reduce entries throws: the merge then skips that entry. Without onError the error is rethrown.

Signature

interface Tree<E = Entry> {
readonly children: readonly Array<Tree<E>>;
readonly entries: readonly Array<E>;
readonly onError?: (error: unknown) => void;
readonly path?: string;
}

Problems

Conflict

unstable
Since v4.2.0

Siblings set the same single slot, such as the title, to different values, and no ancestor's reduce set it. The slot is left unset. paths holds every path that set it, sorted.

Signature

declare class Conflict extends Readonly<{
readonly message: string;
readonly paths: readonly Array<string>;
readonly slot: string;
}> & {
readonly _tag: "HeadConflict";
} & Pipeable {
constructor(args: {
readonly message: string;
readonly paths: readonly Array<string>;
readonly slot: string;
});
}

Utils

Since v4.2.0

The template rule: the title a node passes up. That's the title its children passed up, through the node's own template, or else the node's own title.

Details

entries may hold any vocabulary's entries: only Title and TitleTemplate are read, and the last of each counts. A template that throws is reported to onError and skipped, or rethrown without it.

Signature

declare function resolveTitle(node: {
readonly entries: readonly Array<{
readonly _tag: string;
}>;
readonly onError?: (error: unknown) => void;
}, below: string | undefined): string | undefined