router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)

オープン 初心者向け
#8,887 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@Sheraff がすでに取り組んでいます。

2026年10月25日 から。

  • #8817 @Sheraff による — オープン
  • #8899 @EnesKartal による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript, vite

調査の方向性

packages/router-generator/src/utils.tsから始めて、トップレベルのPrettierのインポートとformat()の呼び出し箇所を調べてください。提案どおり、インポートをformat()内で遅延読み込みするように変更し、その後、フォーマットを対象とするrouter-generatorのテストまたはビルドチェックを実行してください。フォーマットを無効にしたビルドでPrettierが読み込まれなくなり、有効にした場合は引き続きフォーマットが機能すれば完了です。

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

説明

package: router-generator performance
Which project does this relate to?

Router (@tanstack/router-generator, used by @tanstack/router-plugin and TanStack Start)

Describe the problem

packages/router-generator/src/utils.ts imports Prettier at module top level:

import * as prettier from 'prettier'

Prettier is only used by format(), which runs when enableRouteTreeFormatting is true. Because the import is static, every process that loads the generator pays Prettier's module evaluation, even when formatting is disabled. That includes every vite build and vite dev of a TanStack Start app.

Evidence

V8 CPU profiles (vite build --profile, Vite 8.3.6, @tanstack/[email protected]) of two TanStack Start apps in a large monorepo:

App Build wall time Prettier self time Share
A 13.5s 435ms 3.2%
B 7.7s 282ms 3.6%

Almost all of that time is module evaluation with no JS caller, i.e. it's the import, not formatting work.

Suggested change
  1. Load Prettier lazily inside format():
    async function format(source: string, config: Config) {
      const prettier = await import('prettier')
      // ...
    }
    
    This makes the cost zero when formatting is off, and moves it out of startup when it's on.
  2. Optionally, make formatting pluggable (a formatter option, or a documented stable unformatted output) so projects that format generated files with another tool (oxfmt, Biome, dprint) can turn off Prettier without their committed routeTree.gen.ts churning on every build.

Happy to send a PR for (1) if that direction works for you.

主要言語
TypeScript
スター
15.3k
フォーク
1.9k
平均マージ
1日 5時間
マージ済み PR(30日)
46

環境構築

Codespaces で開く

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

はじめの一歩

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

TanStack/router のほかの issue

TanStack/router の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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