Skip to content

feat(pages): let a page's head set or skip titleTemplate - #906

Open
Brooooooklyn wants to merge 1 commit into
mainfrom
feat/page-title-template
Open

Brooooooklyn wants to merge 1 commit into
mainfrom
feat/page-title-template

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Closes #903.

A page whose title already names the site got the suffix twice:

config:  titleTemplate: '%s | My App'
page:    title: 'My App | Q&A'
before:  <title>My App | Q&A | My App</title>
after:   page returns titleTemplate: ''  →  <title>My App | Q&A</title>

Change

template = page.titleTemplate ?? middleware.titleTemplate ?? config.titleTemplate
  • '' drops the template (same rule middleware headDefaults already documents). '%s' also works.
  • Any other string replaces it for that page.
  • defineHead returns HeadConfig (= HeadDescriptor + titleTemplate), so the field type-checks.
  • The template is never sent to the client; only the final title is.

I kept the opt-out as '' rather than adding false/null, so config, middleware and pages share one rule and type.

Tests

  • pages-head.test.ts: page template wins, ''/'%s' skip, page template wraps a lower-layer title, fallback when unset, template not emitted.
  • routing-runtime.test.ts: full page handler with defineHead + middleware + config.
  • New tests fail on main, pass here. vp check and vp run test pass.

Docs

head.md (new "Page title templates" section, precedence table), handlers.md signature, types.md (new HeadConfig entry), config.md table row.

🤖 Generated with Claude Code

A page's `head()` can now return `titleTemplate`. It wins over the
middleware `headDefaults` template and the config template, as the page's
`title` already does. An empty string drops the template, the same rule
middleware follows. `defineHead` now returns `HeadConfig`.

Closes #903.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T14:38:31.263452Z c3d1a11 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-page-title-template-void-cloud.voidzero-docs.workers.dev (commit c3d1a11)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a21def6c-void-cloud.voidzero-docs.workers.dev c3d1a11 2026-11-23T14:38:44.226Z Visit the dashboard ↗

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let a page's head set or skip titleTemplate

1 participant