Repository navigation
fix(router-plugin): work out shared bindings when a split chunk compiles first - #8756
shkumbinhasani wants to merge 1 commit into
Conversation
…les first Split and shared modules read the bindings their route shares from a map that compiling the route file fills. When a `?tsr-split=` or `?tsr-shared=1` module compiled first in a process, as when a dev server serves the route file's output from a cache, the map was empty: the chunk declared its own copy of the shared bindings, and the shared module was left as the untouched route file. `getSharedBindings` now computes them from the module's source with the same groupings the route file uses (`getSplitGroupings`, moved out of the reference handler) and records them. The reference compile also records routes without shared bindings, so chunks of those routes don't compute them again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 47f683b 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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
🎯 Changes
Fixes #8754.
The split (
?tsr-split=…) and shared (?tsr-shared=1) handlers read a route's shared bindings fromsharedBindingsMap, 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.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.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
🚀 Release Impact
🤖 Generated with Claude Code
Summary by CodeRabbit