Skip to content

feat(pages): let _not-found and _error declare their title - #965

Open
harshbhx wants to merge 1 commit into
voidzero-dev:mainfrom
harshbhx:feat/825-boundary-head-title
Open

harshbhx wants to merge 1 commit into
voidzero-dev:mainfrom
harshbhx:feat/825-boundary-head-title

Conversation

@harshbhx

Copy link
Copy Markdown
Contributor

Closes the second half of #825

Summary

_not-found and _error can now set their own page title with export const head = { title: '...' }. The first half of the issue (applying titleTemplate to the default titles) already shipped in #827.

Problem

The error pages could not say "Page not found" to match their heading. renderPageFailure() (packages/void/src/pages/protocol.ts) only had the built-in Not Found / Internal Server Error titles, and boundary components have no .server companion to export a head() from.

Solution

The component declares the title as an object literal. The scan reads it from source (like layout, so no component is loaded), the boundary manifest carries it per render plan, and renderPageFailure() resolves it through resolveHead() as the page title. titleTemplate from config or middleware applies as for any page, and it wins over a middleware headDefaults.title the way a page title does. Boundaries that declare nothing keep today's titles.

Only a static { title: '<string>' } is read. Anything else (variables, extra fields, functions, let) is ignored with a warning that shows the supported form, instead of silently dropping it. A status-dependent function would need the component module at render time, so I kept that out of this PR.

Changes

File Change
packages/void/src/pages/scan.ts, types.ts read head from boundary components (tsx, Vue <script>, Svelte <script module>)
packages/void/src/pages/boundary-plans.ts, router/compile.ts pass the declared titles with the boundary options (pages, root not-found, middleware recovery)
packages/void/src/pages/protocol.ts use the declared title in renderPageFailure()
packages/void/test/unit/page-boundaries.test.ts scan, manifest and protocol tests
docs/guide/pages-routing/errors.md "Page titles" section with all four adapters

Before / After

// pages/_not-found.tsx
export const head = { title: 'Page not found' };

With titleTemplate: '%s | My App': <title>Not Found | My App</title> becomes <title>Page not found | My App</title>.

Testing done

  • New unit tests: static title read from tsx, Vue and Svelte; unreadable forms ignored; heads reach every plan a page can render (nested and root); protocol renders the declared title for 404 and 500, with config and middleware templates, in HTML and Pages-JSON responses; undeclared boundary keeps the default title.
  • Fork CI green (CI, Prepublish Test, Security Analysis): https://github.com/harshbhx/void/actions/runs/46188408778
  • Not tested in a browser or a deployed app. The four adapters are covered through the shared scan and protocol code, not each adapter's integration build.

Notes for reviewers

  • Client-side navigation reuses the same page object, so the title also applies there.
  • If you would rather have the function form or a different export name, I can rework it.

…dev#825)

A boundary component can export head = { title } as an object literal. Void reads it from the source and uses it as the page title, so titleTemplate applies to it like any other page.

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.

1 participant