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

Aperta Adatta ai principianti
#8,887 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Sheraff ci sta già lavorando.

Dal 25/10/2026.

  • #8817 di @Sheraff — aperta
  • #8899 di @EnesKartal — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript, vite

Direzione di ricerca

Inizia da packages/router-generator/src/utils.ts e controlla l’importazione di Prettier a livello superiore e i punti in cui viene chiamato format(). Rendi l’importazione lazy all’interno di format(), come proposto, poi esegui i test del router-generator o i controlli di build che coprono la formattazione. Il lavoro è completato quando le build con la formattazione disabilitata non caricano più Prettier, mentre la formattazione continua a funzionare quando è abilitata.

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

Descrizione

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.

Lingua principale
TypeScript
Stelle
15.3k
Fork
1.9k
Merge medio
1g 5h
PR unite (30g)
46

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 TanStack/router

Tutte le issue di TanStack/router

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.