TanStack / TanStack/cli

[Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration)

Aperta
#480 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
1.3k
Fork
185
Merge medio
18h 45m
PR unite (30g)
2

Descrizione

Which project does this relate to?

Create Tanstack App

Describe the bug

When scaffolding a Router-only SPA (create --router-only), the generated src/router.tsx exports a getRouter() factory, but the generated src/main.tsx does not use it. Instead, main.tsx builds its own router inline with createRouter(...).

As a result:

  1. router.tsx / getRouter() is dead code - nothing imports it anywhere in a --router-only project.
  2. The declare module '@tanstack/react-router' { interface Register { ... } } block is duplicated in both main.tsx (router: typeof router) and router.tsx (router: ReturnType<typeof getRouter>).

In the default (TanStack Start) mode this is fine because Start consumes getRouter() from router.tsx as the entry, and main.tsx is not generated. But in --router-only mode the two files diverge and router.tsx is left orphaned.

Your Example Website or App

pnpx @tanstack/cli create --router-only

Steps to Reproduce the Bug or Issue
  1. pnpx @tanstack/cli create --router-only
  2. Open src/main.tsx and src/router.tsx
  3. Grep the project for getRouter -> only defined in router.tsx, never imported
    (No StackBlitz needed - this is reproducible purely from the CLI output.)
Expected behavior

In --router-only mode, main.tsx should import and use getRouter() from router.tsx, and the Register module augmentation should live in a single place (router.tsx). Something like:

import ReactDOM from 'react-dom/client'
import { RouterProvider } from '@tanstack/react-router'
import { getRouter } from './router'

const router = getRouter()

const rootElement = document.getElementById('app')!

if (!rootElement.innerHTML) {
  const root = ReactDOM.createRoot(rootElement)
  root.render(<RouterProvider router={router} />)
}

This keeps a single source of truth for router configuration across both Start and Router-only modes, removes the dead getRouter(), and removes the duplicate Register declaration.

Screenshots or Videos

No response

Platform
  • OS: macOS
  • @tanstack/cli: 0.69.5
Additional context
  • packages/create/src/frameworks/react/project/base/src/main.tsx.ejs
  • Line 1: <% if (!routerOnly) { ignoreFile() } %> -> only emitted for router-only
  • Lines 6-16: creates its own router + declares Register instead of importing getRouter
  • packages/create/src/frameworks/react/project/base/src/router.tsx.ejs
  • No ignoreFile() guard -> always emitted, exports getRouter() + declares Register

The Solid templates have an identical structure:

  • packages/create/src/frameworks/solid/project/base/src/main.tsx.ejs
  • packages/create/src/frameworks/solid/project/base/src/router.tsx.ejs

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia da packages/create/src/frameworks/react/project/base/src/main.tsx.ejs e router.tsx.ejs, quindi confronta i template Solid corrispondenti. Esegui la CLI con --router-only e ispeziona i file generati; il lavoro è completato quando main.tsx usa getRouter() e la configurazione del router e la dichiarazione di Register non sono più duplicate nel progetto generato.

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

Valutazione

Stack tecnologico
typescript
Ambito
cli, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
76/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.