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

Aperta
#825 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
full-stack

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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>.
Lingua principale
TypeScript
Stelle
684
Fork
83
Merge medio
15h 22m
PR unite (30g)
219

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di voidzero-dev/void

Tutte le issue di voidzero-dev/void

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.