Skip to content

Let a page's head set or skip titleTemplate #903

Open

Description

@karthickeyan-dev

Version

void 1.11.0

Problem

head.titleTemplate in void.config.ts, or headDefaults.titleTemplate set in middleware, wraps every page's title, and a page can't replace or skip it. A page whose title already names the app gets the name twice:

// void.config.ts
export default defineConfig({
  head: { titleTemplate: '%s | My App' },
});
// pages/about.server.ts
export const head = defineHead(() => ({ title: 'About' }));
// pages/index.server.ts
export const head = defineHead(() => ({ title: 'My App | Topic-wise Questions & Answers' }));
Path <title>
/about About | My App
/ My App | Topic-wise Questions & Answers | My App

Home pages and landing pages often lead with the brand, or use a title written for search results that must stay as it is. Today an app with even one such page has to drop titleTemplate and add the suffix to every other page by hand.

Relevant implementation

resolveHead() in packages/void/src/pages/head.ts reads the template only from the middleware and config layers:

const title = pageHead?.title ?? middlewareHead?.title ?? configHead?.title;
if (title !== undefined) {
  const template = middlewareHead?.titleTemplate ?? configHead?.titleTemplate;
  result.title = template ? template.replace('%s', () => title) : title;
}

Since #796, middleware can set headDefaults.titleTemplate for each request, so an app could skip the template by matching the page's path in middleware. But that moves a page's own head out of the page, and a middleware path list goes stale when pages are added or moved.

Proposal

Let a page's head set titleTemplate, with the page taking precedence as it already does for title:

const template =
  pageHead?.titleTemplate ?? middlewareHead?.titleTemplate ?? configHead?.titleTemplate;

and widen the type a page head returns from HeadDescriptor to HeadConfig.

A page then skips the template with '%s', which already works, or uses a template of its own:

// pages/index.server.ts
export const head = defineHead(() => ({
  title: 'My App | Topic-wise Questions & Answers',
  titleTemplate: '%s',
}));

If you'd rather have an explicit opt-out, titleTemplate: false (or null) would also read clearly, but it needs a check other than ??, since ?? passes null through to the next layer.

Prior art

  • Next.js: title: { absolute: '…' } in a page's metadata skips the parent layout's title.template.
  • Nuxt / Unhead: useHead({ titleTemplate: null }) in a page disables the app's template, and useHead({ titleTemplate: '%s – Docs' }) replaces it.
  • TanStack Start: each route's head() sets its whole title, so there's no template to escape.

Workaround

Leave titleTemplate unset and add the suffix in a helper that every page's head calls. It works, but every new page has to remember it, and Void's own titles, such as the default 404 and 500 titles, don't get the suffix (see #825).

Environment: Void 1.11.0, @void/react 1.11.0, TypeScript 7.0.2, Node 26.13.1, macOS.

Activity

  1. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions