fix(start-plugin-core): preload transitive static imports of route chunks #8520
main fromrefs/pull/8520/head·opened Fixes #8511.
🎯 Changes#
Rollup puts a chunk's transitive static imports in chunk.imports. Rolldown (Vite 8) lists only the direct ones, so getChunkPreloads missed any chunk two or more levels deep, and the browser requested it only after the importing chunk had loaded.
getChunkPreloads now walks the static import graph using the scanned chunk map. The chunk and its direct imports come first, in their current order, and each file appears once even when imports form a cycle. Dynamic imports are still excluded. Rollup builds produce the same list as before.
I added a test in manifestBuilder.test.ts. It fails on main and passes with this change. I only ran that test file locally, not the whole workspace suite.
✅ 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).
- 1
Measured this approach on a Start app (rolldown): with the transitive closure preloaded at the default High priority, the stylesheets share the HTTP/2 connection with every chunk and first paint waits for all the JS (FCP 1.78 s → 4.65 s on emulated slow 4G, 47 → 143 preloads). With
fetchPriority="low"from #8212 it drops to 0.87 s and hydration is not delayed. Numbers: https://github.com/TanStack/router/pull/8212#issuecomment-5882406211. Probably worth landing the two together.Thanks for the numbers. Without the closure, a route's second-level chunks load as a waterfall (#8511). With it, on a graph this big, the preloads compete with the stylesheets for the connection. So I agree the two should land together, since #8520 alone makes first paint worse for an app like yours. I can rebase this on #8212 once it's merged, or add the same
fetchPriority="low"here if that's easier to review as one change.
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
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:
2743a319-8ce0-4556-bccf-4a274bd5295c📥 Commits
Reviewing files that changed from the base of the PR and between 5ed733035bc8ccc05191ca53e36b257354e39189 and f7442fb040b0f57441158b33cf6d7821a85e05cd.
📒 Files selected for processing (3)
.changeset/transitive-route-preloads.mdpackages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.tspackages/start-plugin-core/tests/start-manifest-plugin/manifestBuilder.test.ts🚧 Files skipped from review as they are similar to previous changes (1)
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
Walkthrough#
Manifest preload lists now include the transitive closure of static imports. The resolver uses the scanned chunk map to traverse imports, preserve their order, and skip duplicates and cycles. Tests cover route and entry chunks, including shared imports and dynamic-import exclusion.
Changes#
Static import preloads
packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.tsbuildStartManifestpasses the scanned chunk map tocreateManifestAssetResolvers, which accepts it as an optional parameter.packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts,packages/start-plugin-core/tests/start-manifest-plugin/manifestBuilder.test.ts,.changeset/transitive-route-preloads.mdPriority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
f7442The preload change appears mergeable after normal checks; no specific issue requiring correction is identified.
Architecture Summary#
Architecture risk: 🔵 Low · up to
f7442The change affects 1 system.
Changed systems:
packages/start-plugin-coreArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
Before / after behavior
buildStartManifestnow passes the scanned chunks-by-filename map to the asset resolver.createManifestAssetResolversadds an optionalchunksByFileNamemap parameter.buildStartManifesttest asserting ordered preloads for the root entry’s transitive static imports and the/aboutroute’s transitive static imports. The fixture includes a shared dependency, a static-import cycle, and a dynamic import; the expected arrays omit repeated chunks and the dynamic chunk.🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#8511requires transitive static-import preloads and exclusion of dynamic imports.getChunkPreloadsnow performs breadth-first traversal throughchunksByFileName, preserves import order, ski…#8511. The source change updates route preload traversal, the test verifies the required behavior, and the changeset documents the package fix. No unrelated behavior is i…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. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
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