[Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 76/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Calme
- Stack technique
- typescript
Piste de recherche
Commencez par packages/create/src/frameworks/react/project/base/src/main.tsx.ejs et router.tsx.ejs, puis comparez les templates Solid correspondants. Exécutez la CLI avec --router-only et inspectez les fichiers générés ; c’est terminé lorsque main.tsx utilise getRouter() et que la configuration du routeur ainsi que la déclaration de Register ne sont plus dupliquées dans le projet généré.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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:
router.tsx/getRouter()is dead code - nothing imports it anywhere in a--router-onlyproject.- The
declare module '@tanstack/react-router' { interface Register { ... } }block is duplicated in bothmain.tsx(router: typeof router) androuter.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
pnpx @tanstack/cli create --router-only- Open
src/main.tsxandsrc/router.tsx - Grep the project for
getRouter-> only defined inrouter.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+ declaresRegisterinstead of importinggetRouter packages/create/src/frameworks/react/project/base/src/router.tsx.ejs- No
ignoreFile()guard -> always emitted, exportsgetRouter()+ declaresRegister
The Solid templates have an identical structure:
packages/create/src/frameworks/solid/project/base/src/main.tsx.ejspackages/create/src/frameworks/solid/project/base/src/router.tsx.ejs
- Langage dominant
- TypeScript
- Étoiles
- 1.3k
- Forks
- 185
- Merge moyen
- 18 h 45 min
- PR mergées (30 j)
- 2
Préparer son environnement
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TanStack/cli
-
create: scaffold's unlayered body styles defeat its own @layer base rules (and any shadcn theme)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
-
enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 45/100
-
enhancement
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 68/100
Toutes les issues de TanStack/cli
Issues similaires
-
ADD openalgoOuvertetemplate
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
factory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
vercel/ai#21528 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
bug Needs: Triage :mag:
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
microsoft/fluentui-contrib#671 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
sveltejs/acorn-typescript#150 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100