autoCodeSplitting: imported component used as both component and pendingComponent is left undefined (ReferenceError)

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

维护者通常 1 天内回复

@Sheraff 已经在做这个了。

开始于 2026年10月25日。

  • #8817 来自 @Sheraff —— 未关闭
  • #8939 来自 @EnesKartal —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
67/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript, vite
领域
build-system

调研方向

Start in the router plugin’s auto code splitting transform, which handles route component imports; the issue does not name a source file or test. Reproduce with the examples/react/start-bare route and inspect the built server and client router chunks for the missing Page binding. Done when the imported component remains correctly bound when used as both component and pendingComponent, and the route runs without a ReferenceError.

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

描述

Which project does this relate to?

Start

Describe the bug

With autoCodeSplitting: true, a component that is imported from another module and used as both component and pendingComponent ends up as a free identifier in the built router chunk.

component becomes lazyRouteComponent($$splitComponentImporter, "component"), pendingComponent: Page stays in the main chunk, and the import { Page } is removed. vite build exits 0, but the chunk throws when it is evaluated (server request, or Start prerender):

ReferenceError: Page is not defined
    at file:///.../dist/server/assets/router-DsEmb4my.js:40:20
    at ModuleJob.run (node:internal/modules/esm/module_job:569:25)
    at async node:internal/modules/esm/loader:650:26
    at async Promise.all (index 0)
    at async loadEntries (file:///.../dist/server/server.js:6766:52)

The client chunk has the same pendingComponent:Page with no binding.

Not affected: a component declared in the route file and used for both keys (it goes to a ?tsr-shared=1 module), and a separate pending component.

// src/routes/about.tsx
import { createFileRoute } from '@tanstack/react-router'
import { Page } from '~/components/Page'

export const Route = createFileRoute('/about')({
  loader: () => new Promise((r) => setTimeout(r, 500)),
  component: Page,
  pendingComponent: Page,
})

Built server chunk:

var Route = createFileRoute("/about")({
	loader: () => new Promise((r) => setTimeout(r, 500)),
	component: lazyRouteComponent($$splitComponentImporter, "component"),
	pendingComponent: Page
});

Workaround: codeSplitGroupings: [['component', 'pendingComponent']] on the route.

Complete minimal reproducer

https://github.com/cpeaustriajc/tanstack-router-shared-pending-component-repro

Steps to Reproduce the Bug

The repo is examples/react/start-bare with src/routes/about.tsx changed and src/components/Page.tsx added.

  1. pnpm install
  2. pnpm vite build
  3. grep -n pendingComponent dist/server/assets/router-*.js shows pendingComponent: Page, and the chunk has no import or declaration of Page.
  4. pnpm start and open /about: ReferenceError: Page is not defined.

Control: change to pendingComponent: () => <p>Loading</p>. The build output has no free identifier and /about renders.

Expected behavior

The import stays in the main chunk while pendingComponent (not split) still references it, or the binding is shared the same way as a component declared in the route file.

Screenshots or Videos

No response

Platform
  • Router / Start Version: @tanstack/react-router 1.170.46, @tanstack/react-start 1.169.5, @tanstack/router-plugin 1.169.0, @tanstack/start-plugin-core 1.171.56 (also seen on router-plugin 1.168.48)
  • OS: macOS
  • Browser: n/a (fails on the server)
  • Browser Version: n/a
  • Bundler: vite
  • Bundler Version: 8.3.6
  • Node: 26.12.1
Additional context

This issue was written with an AI assistant (Claude) and checked by running the reproducer from a fresh clone.

主要语言
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 摘要。