prerender: allow handlers to skip a route at runtime

Aperta
#4,624 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
build-system

Direzione di ricerca

Inizia tracciando il flow v3 prerender() e l’hook prerender:generate descritti nell’issue, incluso il modo in cui vengono gestiti response headers, route.skip, failedRoutes e il crawling dei link. Determina come un segnale di skip a livello di handler possa raggiungere questo flow, quindi verifica che le route saltate non vengano scritte, sottoposte a crawling o trattate come errori, mentre gli errori esistenti rimangano rilevabili.

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

Descrizione

discussion prerender
Describe the feature

A handler should be able to tell the prerenderer "don't write this route, it's served at runtime" while it handles the prerender request.

Use case: the app only learns which routes are dynamic when it handles them, e.g. a content-driven site where a page's frontmatter says prerender: false. With crawlLinks: true, links to those routes are found and fetched, and the handler knows (via import.meta.prerender / the x-nitro-prerender request header) that it's being prerendered, but it has no clean way to opt out.

What happens today (v3 prerender()):

  • Status other than 200/3xx → route.error → added to failedRoutes → fails the build with failOnError: true. With failOnError: false it is effectively skipped, but real errors are no longer caught.
  • 3xx → accepted and written to disk.
  • The x-nitro-prerender response header can only add routes.
  • prerender:generate can set route.skip, but the route object has no response headers (only contentType), so a handler signal can't reach it without hacks.

The only way left is duplicating the "which routes are dynamic" logic at build time in prerender:routes + prerender.ignore, which often means loading app data twice (once in the builder, once in the prerender worker).

Possible API (any would work):

  1. A response header, e.g. x-nitro-prerender: false, or a dedicated x-nitro-prerender-skip: 1: the route is marked skipped (not failed), nothing is written, and its links are not crawled.
  2. Expose the response headers on the route object in prerender:generate, so a hook can set route.skip from them.

(1) is simplest for handlers:

export default defineEventHandler((event) => {
  if (import.meta.prerender && isDynamic(event)) {
    return new Response(null, { status: 204, headers: { "x-nitro-prerender": "false" } });
  }
  // ...
});

Skipped routes should probably be logged like ignored ones and kept out of failedRoutes.

Additional information
  • Would you be willing to help implement this feature?

[!NOTE]
This issue was drafted with an AI assistant and reviewed before posting.

🤖 Generated with AI assistant

Lingua principale
TypeScript
Stelle
11.5k
Fork
968
Merge medio
4g 9h
PR unite (30g)
64

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 nitrojs/nitro

Tutte le issue di nitrojs/nitro

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.