Skip to content

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

Description

@cpeaustriajc

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions