Start: the Vite plugin and `tsr generate` write different routeTree.gen.ts (Start footer added, then stripped)

未关闭
#8,437 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript, vite

调研方向

从 start-router-plugin/route-tree-footer.ts、scaffold 的 router.tsx 和 generate-routes 脚本开始;使用链接的最小复现示例,比较 build 和 tsr generate 之后的 routeTree.gen.ts。在选择受影响的 package 之前,检查 Router CLI 的安装指南和相关 issue #7768。完成的标准是,Start scaffold 不再在这两个命令之间切换 routeTree.gen.ts,并且文档化的 workflow 保持一致。

由索引模型根据 Issue 内容生成。

描述

enhancement
Which project does this relate to?

Start

Describe the bug

The TanStack Start Vite plugin and the Router CLI write different routeTree.gen.ts files for the same project, and the scaffold produced by tanstack create ships both.

The Start plugin (@tanstack/start-plugin-core, start-router-plugin/route-tree-footer.ts) appends a footer to the generated route tree:

import type { getRouter } from './router.tsx'
import type { createStart } from '@tanstack/react-start'
declare module '@tanstack/react-start' {
  interface Register {
    ssr: true
    router: Awaited<ReturnType<typeof getRouter>>
  }
}

tsr generate (@tanstack/router-cli) does not know about Start and writes the file without it. So every vite build or vite dev adds the nine lines and every tsr generate removes them. In a project that commits routeTree.gen.ts, the file flips on every run of whichever tool ran last.

The scaffold's router.tsx still carries declare module '@tanstack/react-router' { interface Register { router } }, which masks the problem for the router registration. The ssr: true registration has no such fallback: after tsr generate, RegisteredSsr is false, so the serialisable-loader-result check (ValidateSerializableLifecycleResult) silently degrades to any until the next Vite run puts the footer back.

Complete minimal reproducer

https://github.com/TheBinaryGuy/tanstack-start-tsr-footer-repro (the unmodified tanstack create output plus a repro script; bun install && bun run repro shows the diff after each step). Open in StackBlitz: https://stackblitz.com/github/TheBinaryGuy/tanstack-start-tsr-footer-repro

Steps to Reproduce the Bug
npx @tanstack/cli@latest create start-ref --framework React --package-manager bun --non-interactive --no-examples --no-toolchain --deployment nitro
cd start-ref
git add -A && git commit -qm scaffold
bun run build                 # Start plugin: routeTree.gen.ts gains the 9-line footer
git diff --stat src/routeTree.gen.ts
bun run generate-routes       # the scaffold's own `tsr generate` script: footer removed again
git diff --stat src/routeTree.gen.ts
bun run build                 # footer added again
git diff --stat src/routeTree.gen.ts

Observed with @tanstack/react-start 1.168.54, @tanstack/start-plugin-core 1.171.44, @tanstack/router-cli 1.167.36 (and the same with 1.168.49 / 1.171.39 / 1.167.33).

Expected behavior

Both generators produce the same file for a Start project. Either tsr generate reads the Start footer (for example by resolving it the same way the plugin does when @tanstack/react-start is present), or the scaffold does not ship a generate-routes script that undoes what its own build writes, and the Router CLI docs say it is not for Start projects.

Platform
  • OS: macOS 27.0 (arm64)
  • Bun 1.4.0, Node 24
  • Vite 7
Additional context

The Router CLI installation docs already say to use the CLI "only if you are not using a supported bundler", which suggests the fix may be on the scaffold and docs side rather than teaching the CLI about Start. A related report about the Start plugin overriding router generator configuration is #7768.

主要语言
TypeScript
星标
15.3k
派生
1.9k
平均合并
1 天 5 小时
30 天内合并 PR
46

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/router 的其他 Issue

查看 TanStack/router 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。