Skip to content

fix(templates): stop leaking the template's title into published pages#217

Open
hrq-chiuchi wants to merge 1 commit into
CoreBunch:mainfrom
hrq-chiuchi:fix/template-title-leaks-into-published-page
Open

fix(templates): stop leaking the template's title into published pages#217
hrq-chiuchi wants to merge 1 commit into
CoreBunch:mainfrom
hrq-chiuchi:fix/template-title-leaks-into-published-page

Conversation

@hrq-chiuchi

Copy link
Copy Markdown

Summary

  • composeTemplateChain (src/core/templates/templateCompose.ts) always returned title: innermost.title — the title of the innermost template in the chain, never the title of the actual page or entry being rendered.
  • Observed impact: every published page's <title> and derived <head> metadata came from whichever template wrapped it.
    • Ordinary pages (Home, About, Contact, ...) all rendered <title> as the site's "everywhere" template's own title (e.g. "Site Template" for every single page).
    • Post-type entries rendered <title> as the postType template's title (e.g. every blog post showed "Post Template", every event showed "Event Template") instead of the entry's own title.
  • Found while building out a real multi-page site with custom post types — reproduced by comparing <title> across /, /about, an entry page, and its listing page after publish.

Fix

  • For a page terminal, terminal.page is already passed into composeTemplateChain — use its title instead of the template's.
  • For an entry terminal there's no Page object at that layer (the entry's body flows in via dynamicBindings, not a spliced Page), so the two callers that resolve entry routes (renderPublishedDataRowTemplate in server/publish/publicRenderer.ts, and the row preview handler in server/handlers/cms/data/preview.ts) now set merged.title from the row's own title cell immediately after composing, before the page is rendered — following the same typeof cells.title === 'string' pattern already used in src/core/data/pageFromRow.ts.

Test plan

  • bunx tsc -b --noEmit passes
  • bun test passes, including src/core/templates/__tests__/templateCompose.test.ts
  • Manually verified end-to-end on a real site: published every page/entry type (plain page, postType index, postType entry) and confirmed <title> now matches the actual page/entry title rather than the wrapping template's title

composeTemplateChain always returned the innermost TEMPLATE's title as
the merged page's title, never the actual page or entry being
rendered. Every published page's <title> and <head> metadata came from
whichever template wrapped it: ordinary pages all showed the
"everywhere" template's title, and post-type entries showed the
postType template's title instead of the entry's own title.

For a page terminal, terminal.page is already available inside
composeTemplateChain, so use its title directly. For an entry
terminal there is no Page object at that layer, so the two callers
(renderPublishedDataRowTemplate and the row preview handler) set
merged.title from the published/draft row's own title cell right
after composing, before the page is rendered.
@hrq-chiuchi hrq-chiuchi marked this pull request as ready for review July 12, 2026 01:33
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.

1 participant