Skip to content

fix(router-plugin): export a shared binding as-is when a split route option uses it - #8773

Open
dasjideepak wants to merge 1 commit into
TanStack:mainfrom
dasjideepak:fix/split-target-shared-binding
Open

dasjideepak wants to merge 1 commit into
TanStack:mainfrom
dasjideepak:fix/split-target-shared-binding

Conversation

@dasjideepak

@dasjideepak dasjideepak commented Oct 20, 2026 •

Copy link
Copy Markdown

🎯 Changes

Fixes #8715

A split option like notFoundComponent: PostNotFound, where PostNotFound is also used by another split group, made the virtual module export SplitNotFoundComponent without declaring it. It only worked with a single @babel/traverse copy, through the stale scope cache.

Fix: when the option's identifier is a shared binding, export the shared import directly.

import { PostNotFound } from "route.tsx?tsr-shared=1";
export { PostNotFound as notFoundComponent };
  • New test in code-splitter-shared-split-target.test.ts for notFoundComponent and errorComponent. It clears the traverse cache after the first pass, which is what a second traverse copy does. Fails on main, passes with the fix.
  • Also checked with the reporter's repro (https://github.com/Zeifri/tanstack-router-8715-repro) and the two-copy install (@babel/traverse 7.29.8 + 7.29.10): the output now matches the single-copy one.
  • Changeset added (patch).

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

AI disclosure: I used an AI assistant to help write the test and this text. I reproduced the bug, reviewed the change and ran the tests myself.

…option uses it

When a split route option (like notFoundComponent) points to a local
function that another split group also uses, the virtual module exported
SplitNotFoundComponent without declaring it. This happened whenever the
earlier scope cache was not reused, for example with two copies of
@babel/traverse installed.

Fixes TanStack#8715
@changeset-bot

changeset-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 429ff7c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@tanstack/router-plugin Patch
@tanstack/router-vite-plugin Patch
@tanstack/start-plugin-core Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/router/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3e9bd53-4c22-432e-a788-f685f595c9df
📥 Commits

Reviewing files that changed from the base of the PR and between ed55775 and 429ff7c.

📒 Files selected for processing: 3
  • .changeset/shared-split-target-export.md
  • packages/router-plugin/src/core/code-splitter/compilers.ts
  • packages/router-plugin/tests/code-splitter-shared-split-target.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

When a split route option uses a shared binding, the compiler now exports that binding directly. Tests cover notFoundComponent and errorComponent, and a patch changeset documents the fix.

Changes: Shared split-target exports

Layer / File(s) Summary
Preserve shared bindings in split exports
packages/router-plugin/src/core/code-splitter/compilers.ts, packages/router-plugin/tests/code-splitter-shared-split-target.test.ts, .changeset/shared-split-target-export.md
The compiler exports a shared identifier directly instead of resolving its removed declaration. Tests verify shared-binding detection, generated exports, and valid compiled modules for notFoundComponent and errorComponent. The changeset records a patch release for @tanstack/router-plugin.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: schiller-manuel

Merge Risk: ⚪ Minimal · up to 429ff

The shared split-target fix is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: exporting a shared binding unchanged when a split route option uses it.
Linked Issues check Passed Issue #8715 requires correct code splitting when a shared local binding is used by a split route option, including notFoundComponent and errorComponent. The compiler now detects the shared identif…
Out of Scope Changes check Passed The changes are limited to the compiler fix, regression tests for the reported options, and a patch changeset for @tanstack/router-plugin. These changes directly support issue #8715 and do not show …
Description check Passed The pull request description follows the repository template. It explains the change, lists testing and checklist status, documents release impact and the changeset, and discloses AI assistance.
Full details: Linked Issues check

Explanation

Issue #8715 requires correct code splitting when a shared local binding is used by a split route option, including notFoundComponent and errorComponent. The compiler now detects the shared identifier, keeps it linked to the shared import, and exports it directly instead of resolving a removed declaration. The new parameterized test covers both options, clears the Babel traversal cache to model separate traversal copies, and validates the generated modules.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the compiler fix, regression tests for the reported options, and a patch changeset for @tanstack/router-plugin. These changes directly support issue #8715 and do not show unrelated behavior changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

router-plugin: a split route option that is also a shared binding exports an undeclared Split… when two @babel/traverse copies are installed

1 participant