Let `_not-found` and `_error` set their title, and apply `titleTemplate` to the default one

Offen
#825 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
react, typescript
Bereich
full-stack

Rechercherichtung

Start with renderPageFailure() and resolveHead(), where the fallback title is added after the head is resolved, so the template is never applied to it. Check how _not-found and _error are rendered, and whether the second proposal (a head export for error pages) is needed or whether applying the template is enough. Done means a 404 page's <title> reads Not Found | My App when titleTemplate is set, and the existing tests still pass. Confirm the design direction with a maintainer before adding a new export.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Version

void 1.9.0

Problem

With head: { titleTemplate: '%s | My App' } in void.config.ts, every page's tab gets the app name, except the error pages:

Path Status <title>
/ 200 Home | My App
/about 200 About | My App
/no-such-page 404 Not Found

renderPageFailure() resolves the head with no page title, so resolveHead() never applies the template. It then adds its own title after that step:

title: head?.title ?? (status === 404 ? 'Not Found' : 'Internal Server Error')

_not-found and _error can't change this either. They can't have a .server.ts, so they have no head, and a headDefaults.title set in middleware would reach every page that sets no title of its own, not just the error pages. So the error pages can't say "Page not found" to match their heading, and they're the only tabs without the app name.

Proposal
  1. Apply the template to the default title, by passing it through resolveHead() as the page title: Not Found | My App. That's a small change, and it makes these pages match every other page without any code in the app.

  2. Let error pages set their title. For example, a head export from _not-found and _error, taking the error they render:

    // pages/_not-found.tsx
    export const head = { title: 'Page not found' };
    
    // pages/_error.tsx
    export const head = (error: PageError) => ({
      title: error.status === 404 ? 'Page not found' : 'Something went wrong',
    });
    
Prior art
  • Next.js: not-found.tsx can export metadata, and the root layout's title.template applies to it.
  • Nuxt: error.vue calls useHead(), and the app's titleTemplate applies.
  • SvelteKit: +error.svelte sets its title with <svelte:head>.
Vorherrschende Sprache
TypeScript
Sterne
684
Forks
83
Ø Merge
15 Std. 22 Min.
Gemergte PRs (30 T.)
219

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus voidzero-dev/void

Alle Issues in voidzero-dev/void

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.