Repository navigation
feat(pages): allow titleTemplate in middleware headDefaults - #797
Conversation
…ev#796. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0froq
left a comment
There was a problem hiding this comment.
Several additions in the inline comments. The rest looks right. Thank you!
| const title = pageHead?.title ?? middlewareHead?.title ?? configHead?.title; | ||
| if (title !== undefined) { | ||
| const template = configHead?.titleTemplate; | ||
| const template = middlewareHead?.titleTemplate ?? configHead?.titleTemplate; |
There was a problem hiding this comment.
There's no way to drop the site-wide suffix for a section. titleTemplate: '' already does it, since the empty string is falsy and template ? ... : title returns the bare title, but that is load-bearing by accident. Switch the check to template !== undefined and the behaviour disappears while every test stays green.
Two small additions would cover it:
- one case in
pages-head.test.ts:{ titleTemplate: '' }against a config template resolves toUsers. - one line in
head.mdsaying an empty template disables the wrapper
I placed them in suggestions
| user: AuthUser | null; | ||
| session: AuthSession | null; | ||
| headDefaults?: HeadDescriptor; | ||
| headDefaults?: HeadConfig; |
There was a problem hiding this comment.
HeadConfig isn't exported from void while HeadDescriptor is (src/index.ts). Anyone wrapping defineMiddleware for a typed helper has to cast or redeclare the shape. Exporting it next to HeadDescriptor keeps the new public type nameable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: froQ <sayhola@froq.me> Signed-off-by: Christoph Nakazawa <xnakazawa@pm.me>
Co-authored-by: froQ <sayhola@froq.me> Signed-off-by: Christoph Nakazawa <xnakazawa@pm.me>
Closes #796
Summary
titleTemplatecould only be set once, for the whole site, invoid.config.ts.headDefaultswas typedHeadDescriptor, which has notitleTemplate, andresolveHead()read the template only from the config. So one section of a site couldn't have its own title suffix.packages/void/src/runtime/handler.ts:headDefaultsis now typedHeadConfig, soc.set('headDefaults', { titleTemplate })type-checks.packages/void/src/pages/head.ts:resolveHead()uses the middleware'stitleTemplateand falls back to the config's. The resolved head still doesn't includetitleTemplate.packages/void/src/pages/protocol.ts: the threeheadDefaultsreads cast toHeadConfig.docs/guide/pages-routing/head.md: an example under Middleware defaults, and thetitlerow in the precedence table.A page returning
{ title: "Users" }under/adminnow renders<title>Users | Admin</title>. Sites that don't settitleTemplatein middleware see no change.Tests
pages-head.test.ts: the middleware template wins over the config's, applies when the config has none, falls back to the config's when middleware doesn't set one, and isn't emitted in the resolved head.routing-runtime.test.ts: adefineMiddlewareon/admin/*sets the template, andcreatePageGetHandlerreturnsUsers | Adminunder/adminandUsers | My Siteelsewhere.4 of the new cases fail without the fix. Without the fix, the runtime test also fails to type-check (
TS2769onc.set).Verification
vp run check: 33/33 passvp test run: 792 files pass, 1 skipped (16,676 tests pass, 37 skipped)🤖 Generated with Claude Code