Skip to content

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

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

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

Conversation

@harshbhx

@harshbhx harshbhx commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes the second half of #825

Summary

_not-found and _error can now set their own page title (and any other head field) with a head() exported from an optional .server companion. The first half of the issue (applying titleTemplate to the default titles) already shipped in #827.

// pages/_error.server.ts (or pages/_not-found.server.ts)
import { defineHead } from 'void/handler';
import type { ErrorPageProps } from 'void/pages';

export const head = defineHead<ErrorPageProps>((c, { error }) => ({
  title: error.status === 404 ? 'Page not found' : 'Something went wrong',
}));

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

How it works

pages/_error.server.ts ──scan──▶ boundary.serverPath   (loader/action exports → error)
                                      │
router compile ──▶ const __voidBoundaryHeads = { <plan id>: lazy import }   (emitted once)
                                      │
route options ──▶ boundaryHeads: __voidBoundaryHeads ──▶ renderOptions.boundaries.loadHeads
                                      │
renderPageFailure() ──▶ head(c, { error }) ──▶ resolveHead(config, middleware, head)
                         │ import / head() / reading or rendering the result fails
                         └──▶ log it, keep the default title (status unchanged)
  • Boundaries without a companion keep today's titles and titleTemplate behavior.
  • A head() with no title keeps the default title.
  • The companion never reaches the client manifest.
  • .dev / .prod boundary files and their companions are filtered by environment in binding inference, so a dev-only _error.dev.server.ts that imports void/db doesn't make a production deploy create D1.

Changes

File Change
packages/void/src/pages/scan.ts, types.ts record a boundary's .server companion; reject loader/action exports; pageFileEnvironment reads boundary files
packages/void/src/pages/boundary-plans.ts keep serverPath out of the client boundary plans
packages/void/src/router/compile.ts one shared loader map for boundary heads
packages/void/src/runtime/routing/pages.ts pass the loaders into GET, mutation and middleware-error recovery
packages/void/src/pages/protocol.ts run head(), resolve and render-check its result inside one recovery guard
packages/void/src/application-analysis.ts add boundary companions to the dev Worker dependency scan
docs/guide/pages-routing/errors.md, design doc 0093 "Page titles" section

Testing done

  • Unit: scan, manifest, compile (loader map emitted once), binding inference (dev-only boundary), protocol (404/500, middleware template, no title, no head, import failure, head() throws, title getter throws, values the HTML head can't render), in HTML and Pages-JSON responses.
  • Integration: the shared page-errors suite uses a _not-found.server.ts title for all four adapters.
  • Dev Worker dependency scan includes boundary companions (plugin-vite-environment.test.ts).
  • vp check, vp run test (189/189), vpr test:all, local codex review.

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the titles and title template behavior we already shipped and build custom error-page titles around the existing head() convention instead.

@harshbhx

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @cpojer. Just to make sure I rework it the way you mean: boundaries like _not-found and _error can't have a .server.ts today, so there's nowhere to export head() from. Which of these do you prefer?

  1. Allow an optional _not-found.server.ts / _error.server.ts that exports the usual head() (taking the Hono context, and the error for _error), and run it in renderPageFailure() through resolveHead() like any page.
  2. Keep the component-level export, but make it the same defineHead shape instead of a static object.

I'd lean towards 1. The default Not Found / Internal Server Error titles and the template behaviour from #827 stay untouched either way. I'll hold off on changes until you say which way you'd like it.

@cpojer

cpojer commented Nov 29, 2026

Copy link
Copy Markdown
Member

Yep, let's do 1.

@cpojer cpojer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slop Review:

  • The void package fails typechecking. The boundary options type is missing loadHeads, and a new test reads .head from a value typed as unknown. The base commit passes the same typecheck. [Boundary lookup](codex://review?pr=https%3A%2F%2Fgithub.com%2Fvoidzero-dev%2Fvoid%2Fpull%2F965&path=packages%2Fvoid%2Fsrc%2Fpages%2Fprotocol.ts&line=557&side=right)
  • One root boundary makes generated router code grow quadratically. With 300 routes and one boundary companion, generated source grew from 217 KB to 5.86 MB before bundling. Every route embeds the full loader map. Emit the map once and share it. [Router generation](codex://review?pr=https%3A%2F%2Fgithub.com%2Fvoidzero-dev%2Fvoid%2Fpull%2F965&path=packages%2Fvoid%2Fsrc%2Frouter%2Fcompile.ts&line=1081&side=right)
  • A dev-only boundary can trigger production D1 provisioning. I reproduced this with a void/db import in _error.dev.server.ts. The production route scan excludes the boundary, but binding inference still sees the import. [Companion discovery](codex://review?pr=https%3A%2F%2Fgithub.com%2Fvoidzero-dev%2Fvoid%2Fpull%2F965&path=packages%2Fvoid%2Fsrc%2Fpages%2Fscan.ts&line=366&side=right)
  • A failure while resolving the returned title can turn a 404 into a 500. A throwing title getter reproduced this. Resolve the returned metadata inside the same recovery guard as head(). [Title resolution](codex://review?pr=https%3A%2F%2Fgithub.com%2Fvoidzero-dev%2Fvoid%2Fpull%2F965&path=packages%2Fvoid%2Fsrc%2Fpages%2Fprotocol.ts&line=559&side=right)

harshbhx and others added 4 commits December 1, 2026 21:48
- Type the boundary head loaders on the render options, and the test payload.
- Emit the boundary head loader map once instead of inside every route.
- Filter dev/prod boundary files and their .server companions in binding inference.
- Resolve what head() returns inside the same recovery guard as the call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…boundary names

- Add boundary .server companions to the dev Worker dependency scan, like page companions.
- pageFileEnvironment() treats only exact _error/_not-found files as boundaries, so
  ignored helpers such as _error.data.dev.server.ts keep their bindings.
- Describe the companion head() in design doc 0093.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e can't render

A head() that returns, say, a number meta content passed the payload check but
failed later in the HTML head render, outside the guard, turning a 404 into a 500.
Render the head inside the guard so such values fall back like other failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/825-boundary-head-title branch from 9b5ab66 to 40c23cc Compare December 1, 2026 14:37
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 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-12-01T14:43:21.222139Z 40c23cc Manual request
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 40c23cc00c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn requested a review from cpojer December 1, 2026 14:47
@harshbhx

harshbhx commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up commits, I went through them against the four points and they cover everything, so I'm not adding anything on top:

  • typecheck: loadHeads is on the boundary options type and the test's page data is typed
  • the loader map is emitted once and shared by every route (with a compile test)
  • dev-only boundaries (_error.dev.*, and their .server companions) no longer count toward production binding inference, so no D1 for them
  • a throwing title getter, or a head value that can't render, falls back to the default head, so a 404 stays a 404

Happy with it as is.

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.

3 participants