Skip to content
Source
Sign inSign up
TanStack/router

fix(start-plugin-core): preload transitive static imports of route chunks #8520

ClosedTiagoGranelli(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8520/headopened

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. Review in Change Stack →

      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.md
      • packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts
      • packages/start-plugin-core/tests/start-manifest-plugin/manifestBuilder.test.ts
      🚧 Files skipped from review as they are similar to previous changes (1)
      • .changeset/transitive-route-preloads.md

      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

      Layer / File(s)Summary
      Pass the scanned chunk map
      packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts
      buildStartManifest passes the scanned chunk map to createManifestAssetResolvers, which accepts it as an optional parameter.
      Traverse and test static imports
      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.md
      Preload collection traverses the static import graph breadth-first, preserving import order and skipping duplicate filenames and cycles. The test covers route and entry chunks, shared imports, and dynamic-import exclusion. The changeset describes the update.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Merge Risk: ⚪ Minimal · up to f7442

      The preload change appears mergeable after normal checks; no specific issue requiring correction is identified.

      Architecture Summary

      Architecture risk: 🔵 Low · up to f7442

      The change affects 1 system.

      Changed systems: packages/start-plugin-core

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — packages/start-plugin-core (library) was modified; 2 changed files map to changed impact.

      Before / after behavior

      • observed — Modified behavior in packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts: buildStartManifest now passes the scanned chunks-by-filename map to the asset resolver.
      • observed — Modified behavior in packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts: createManifestAssetResolvers adds an optional chunksByFileName map parameter.
      • observed — Modified behavior in packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts: Chunk preloads now traverse the static import graph, starting with the chunk and its direct imports. A set preserves first-seen order and avoids duplicate filenames; imports are followed only when the optional map contains the corresponding chunk. This replaces the prior list of only the chunk and its direct imports.
      • observed — Modified behavior in packages/start-plugin-core/tests/start-manifest-plugin/manifestBuilder.test.ts: Adds a buildStartManifest test asserting ordered preloads for the root entry’s transitive static imports and the /about route’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)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 …Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedIssue #8511 requires transitive static-import preloads and exclusion of dynamic imports. getChunkPreloads now performs breadth-first traversal through chunksByFileName, preserves import order, ski…
      Out of Scope Changes check✅ PassedThe changes stay within issue #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…
      Title check✅ PassedThe title clearly and concisely describes the main change: preloading transitive static imports for route chunks in start-plugin-core.
      Description check✅ PassedThe description follows the required template, explains the motivation and implementation, records testing scope, completes the checklist, and documents the changeset for published code.
      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.)

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      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.
    2. 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.

    3. 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.