prerender: allow handlers to skip a route at runtime

オープン
#4,624 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
build-system

調査の方向性

まず、issue に記載されている v3 prerender() flow と prerender:generate hook を追跡し、response headers、route.skip、failedRoutes、リンクのクロールがどのように処理されるかを確認します。handler-level の skip signal がその flow に到達する方法を特定し、skip されたルートが書き込まれず、クロールされず、失敗として扱われない一方で、既存のエラーは引き続き検出可能であることを検証します。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
11.5k
フォーク
968
平均マージ
4日 9時間
マージ済み PR(30日)
64

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nitrojs/nitro のほかの issue

nitrojs/nitro の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。