fix(router-plugin): export a shared binding as-is when a split route option uses it #8773
main fromrefs/pull/8773/head·opened 🎯 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.tsfornotFoundComponentanderrorComponent. 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/traverse7.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.
- 1
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 ed5577593a749b8c7193cc7b5d945fd084bfac2f and 429ff7c5970324146efffac6fcc982aad3ab5d50.
📒 Files selected for processing: 3
-
.changeset/shared-split-target-export.mdpackages/router-plugin/src/core/code-splitter/compilers.tspackages/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
notFoundComponentanderrorComponent, 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.mdThe compiler exports a shared identifier directly instead of resolving its removed declaration. Tests verify shared-binding detection, generated exports, and valid compiled modules for notFoundComponentanderrorComponent. 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:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage 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 checks: 4 passed-
Check name Status Explanation Title check The title clearly and concisely describes the primary change: exporting a shared binding unchanged when a split route option uses it. Linked Issues check Issue #8715requires correct code splitting when a shared local binding is used by a split route option, includingnotFoundComponentanderrorComponent. The compiler now detects the shared identif…Out of Scope Changes check 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#8715and do not show …Description check 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
#8715requires correct code splitting when a shared local binding is used by a split route option, includingnotFoundComponentanderrorComponent. 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#8715and 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.
Comment `@coderabbitai help` to get the list of available commands.-
dasjideepak(GitHub profile, opens in a new tab) linked this to fix #8715
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 429ff7c5970324146efffac6fcc982aad3ab5d50
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 7 packages
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