fix(router-plugin): work out shared bindings when a split chunk compiles first #8756
main fromrefs/pull/8756/head·opened 🎯 Changes#
Fixes #8754.
The split (?tsr-split=…) and shared (?tsr-shared=1) handlers read a route's shared bindings from sharedBindingsMap, which only the reference compile fills. When one of them compiled first in a process, as when a dev server serves the route file's output from a cache, the chunk declared its own copy of the shared bindings, and the shared module was left as the untouched route file.
getSharedBindings(baseId, code)returns the recorded bindings, or computes them from the module's source and records them. The virtual and shared handlers use it.getSplitGroupingsis the grouping lookup (routecodeSplitGroupings, thensplitBehavior, thendefaultBehavior, with the same validation), moved out ofhandleCompilingReferenceFileso both paths use it.- The reference compile now records an empty set for a route without shared bindings instead of deleting its entry, so that route's chunks don't compute the bindings again.
ARCHITECTURE-CODE-SPLITTING.mddescribes the fallback.
In the usual order (route file first) nothing changes: the handlers read what the reference compile recorded. #8504 drops the map and computes the bindings in each handler (resolveSharedBindings); this keeps the map so the usual order does no extra work.
Tests:
code-splitter-plugin-pipeline.test.ts: compiles a route's chunk and shared module before its route file, and the shared module first, with the default groupings and withsplitBehavior, and expects the same modules as compiling the route file first. Both cases fail onmain.- The reproducer in #8754 gives the same output in both orders with this build.
pnpm nx run @tanstack/router-plugin:test:unit(902 passed, 3 expected fail),test:typesandtest:eslintpass;@tanstack/start-plugin-core:test:unitpasses.
AI disclosure: Claude Code wrote this change, its tests and this description.
✅ 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).
🤖 Generated with Claude Code
Summary by CodeRabbit#
- Bug Fixes
- Fixed code-split output when route files, split chunks, or shared modules are processed in different orders. Builds now preserve consistent shared-binding behavior, including when route output is served from cache.
- Documentation
- Updated code-splitting guidance to reflect how shared bindings are resolved when dependent modules are processed before their route files.
- 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:
cf2ccac3-244e-4584-a73a-e122d23b2962
📥 Commits
-
Reviewing files that changed from the base of the PR and between b1b111761bdfa7a0582f28ea78ee81fe7c59ed99 and 47f683b9715abed502e2a6a770472747a8bc226c.
📒 Files selected for processing: 4
-
.changeset/shared-bindings-before-route-file.mdpackages/router-plugin/ARCHITECTURE-CODE-SPLITTING.mdpackages/router-plugin/src/core/router-code-splitter-plugin.tspackages/router-plugin/tests/code-splitter-plugin-pipeline.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The router plugin now resolves shared bindings when a split chunk or shared module compiles before its route file. It computes and caches bindings from a known route’s source and grouping configuration. Tests compare output across compilation orders.
Changes: Shared-binding resolution
Layer / File(s) Summary Resolve and cache route bindings
packages/router-plugin/src/core/router-code-splitter-plugin.tsThe plugin extracts route grouping resolution and adds a helper that returns cached bindings or computes and stores them for a known route. Use resolved bindings in dependent transforms
packages/router-plugin/src/core/router-code-splitter-plugin.ts,packages/router-plugin/tests/code-splitter-plugin-pipeline.test.ts,packages/router-plugin/ARCHITECTURE-CODE-SPLITTING.md,.changeset/shared-bindings-before-route-file.mdVirtual-route and shared-module transforms use the resolver. Tests compare compilation orders. The architecture documentation and changeset describe the behavior. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
sequenceDiagram participant SplitModuleTransform participant getSharedBindings participant sharedBindingsMap participant RouteSource SplitModuleTransform->>getSharedBindings: Resolve bindings for the route getSharedBindings->>sharedBindingsMap: Look up cached bindings alt Cache miss getSharedBindings->>RouteSource: Read source and route grouping configuration getSharedBindings->>sharedBindingsMap: Store computed bindings end getSharedBindings-->>SplitModuleTransform: Return bindings or undefinedSuggested reviewers:
schiller-manuel,sheraff
Merge Risk: ⚪ Minimal · up to
47f68-
The change makes split chunk and shared module output independent of compile order. No actionable merge-blocking risk was identified.
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 2 functions across 2 files. (2 skipped: 2 … 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 main fix: resolving shared bindings when a split chunk compiles before its route file. Description check The description follows the required template. It explains the change and motivation, identifies the issue, documents testing, discloses AI authorship, and includes a changeset. One checklist item rem… Linked Issues check The pull request meets the coding requirements in [ #8754].getSharedBindings()computes and records bindings when a split or shared module runs first.getSplitGroupings()applies the route, `split…Out of Scope Changes check The changes stay within [ #8754]. The implementation fixes order-independent shared bindings. The tests reproduce the reported compile orders. The architecture documentation and changeset document the …Full details: Description check
-
Explanation
The description follows the required template. It explains the change and motivation, identifies the issue, documents testing, discloses AI authorship, and includes a changeset. One checklist item remains unchecked, but the description is otherwise complete.
Full details: Linked Issues check
-
Explanation
The pull request meets the coding requirements in [
#8754].getSharedBindings()computes and records bindings when a split or shared module runs first.getSplitGroupings()applies the route,splitBehavior, and default grouping rules. The reference path records empty binding sets. The virtual and shared handlers use the resolver. The added parameterized tests cover both dependent-module orders and default andsplitBehaviorgroupings.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within [
#8754]. The implementation fixes order-independent shared bindings. The tests reproduce the reported compile orders. The architecture documentation and changeset document the same behavior and release impact. No unrelated product behavior is changed.
-
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 2 functions across 2 files. (2 skipped: 2 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.-
View your CI Pipeline Execution ↗ for commit 47f683b9715abed502e2a6a770472747a8bc226c
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 14m 33s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 29s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-19 07:06:28UTCMore templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsbuild
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-next-migration
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@8756@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8756@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8756@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@8756@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@8756@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@8756@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8756@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@8756@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@8756@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@8756@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@8756@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@8756@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@8756@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@8756@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@8756@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@8756@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@8756@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8756@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@8756@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8756@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@8756@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8756@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8756@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@8756@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@8756@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@8756@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@8756@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8756@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@8756@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@8756@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8756@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@8756@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@8756@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8756@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@8756@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8756@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8756@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@8756@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@8756@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@8756@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@8756commit:
47f683bMerging this PR will improve performance by 9.45%#
:warning: 41 benchmarks spent significant time in system calls
System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.
ssr not-found (vue)ssr head (vue)ssr dehydrate plain control (solid)client-nested-params navigation loop (solid)client-rewrites navigation loop (solid)ssr dehydrate rich types (vue)ssr assets inline-css cdn (solid)ssr assets inline-css cdn (react)ssr head (react)ssr global-mw server-route 1 middleware (vue)- …and 31 more
:information_source: 29 benchmarks have no flame graph
The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.
ssr control-flow error 500 (react)ssr assets inline-css cdn (react)ssr assets linked-css control (react)ssr dehydrate rich types (react)ssr server-fn send-context (react)ssr server-fn raw-response (react)ssr server-fn raw-stream (react)ssr before-load chain (react)ssr not-found (react)ssr global-mw document (react)- …and 19 more
:warning: Different runtime environments detected
Some benchmarks with significant performance changes were compared across different runtime environments, which may affect the accuracy of the results.
⚡ 1improved benchmark✅ 193untouched benchmarks⏩ 3skipped benchmarks1Performance Changes#
Mode Benchmark BASEHEADEfficiency ⚡ Memory mem client navigation-churn (solid)113.8 KB 104 KB +9.45% Tip
Curious why performance improved? Comment
@codspeedbot explain why performance improvedon this PR, or directly use the CodSpeed MCP with your agent.
Comparingshkumbinhasani:fix/router-plugin-shared-bindings-order(47f683b) withmain(b1b1117)Footnotes#
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
shkumbinhasani(GitHub profile, opens in a new tab) linked this to fix #8754
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 47f683b9715abed502e2a6a770472747a8bc226c
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