Skip to content
Source
Sign inSign up
TanStack/router

Start manifest preloads miss transitive chunks with Vite 8 (Rolldown), causing a module waterfall #8548

Closedquanglam2807(GitHub profile, opens in a new tab) opened this issue 1 comment

Which project does this relate to?

Start

Describe the bug

On Vite 8 (Rolldown), the Start manifest leaves out most of a route's JS dependencies from preloads. The browser only finds them as each chunk runs, so they load in a waterfall before hydration.

getChunkPreloads in packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts lists the route chunk plus only its direct chunk.imports:

const preloads = [getAssetPath(chunk.fileName)]
for (let i = 0; i < chunk.imports.length; i++) preloads.push(getAssetPath(chunk.imports[i]))

With Rollup this covered the whole tree, because output.hoistTransitiveImports is on by default and adds transitive imports to an entry chunk's imports. Rolldown doesn't implement it: its option type is hoistTransitiveImports?: false. So chunk.imports is only one level deep, and everything below it is missing from the manifest.

getChunkCssAssets in the same file already walks imports recursively. The JS preloads need the same treatment.

Measured on a production site (Start 1.168.58 / start-plugin-core 1.171.47, still the same code in 1.171.48, Vite 8.3.1, rolldown 1.2.11). For one route:

  • The static import closure (root + layout + route) is 114 chunks. The manifest preloads 71 of them, so 43 are missing.
  • Network trace: the 43 load in three serial rounds (~412 ms, ~509 ms and ~610 ms unthrottled) after the entry chunk finishes at ~342 ms.
  • A/B test serving the same HTML with the missing modulepreload links added: Lighthouse mobile perf 64 → 69 (median of 5), FCP 3.44 s → 2.15 s. Under real devtools throttling, the last JS chunk arrives ~0.7 s sooner.

Complete minimal reproducer

I don't have a standalone repo yet, sorry. It reproduces in any Start app on Vite 8 when a route component imports module A, and A imports module B, with both A and B shared with another route so each gets its own chunk:

  1. vite build.
  2. Open the server build's tanstack-start-manifest and look at the route's preloads: A's chunk is listed, B's is not.
  3. Load the route and watch the network panel: B is requested only after A has been fetched and evaluated.

Happy to put a repo together if that helps.

Steps to Reproduce the Bug

See above.

Expected behavior

A route's preloads include its whole static import closure, so every chunk is requested in parallel from the HTML, as it was with Rollup.

A breadth-first walk over chunk.imports, deduped, fixes it. I tested this by patching the built file; the manifest then preloads all 114 of 114 chunks for that route:

const getChunkPreloads = (chunk) => {
  const cachedPreloads = preloadsByChunk.get(chunk)
  if (cachedPreloads) return cachedPreloads
  const preloads = [getAssetPath(chunk.fileName)]
  const seen = new Set([chunk.fileName])
  const queue = [...chunk.imports]
  while (queue.length > 0) {
    const fileName = queue.shift()
    if (seen.has(fileName)) continue
    seen.add(fileName)
    preloads.push(getAssetPath(fileName))
    const importedChunk = chunksByFileName.get(fileName)
    if (importedChunk) queue.push(...importedChunk.imports)
  }
  preloadsByChunk.set(chunk, preloads)
  return preloads
}

(createManifestAssetResolvers needs chunksByFileName passed in.) With Rollup the extra levels are already in imports, so this changes nothing there. Nested-route dedupe (dedupeNestedRouteManifestEntries) still removes chunks a parent route already preloads.

Platform

  • Router / Start version: @tanstack/react-start 1.168.58, @tanstack/start-plugin-core 1.171.47 (same code in 1.171.48)
  • Bundler: Vite 8.3.1 (rolldown 1.2.11)
  • OS: macOS
  • Browser: Chrome 154

Additional context

The Rspack path (rsbuild/normalized-client-build) may need the same check, but I haven't looked at it.

  1. Duplicate of #8511, which I missed when I searched. The fix is in #8520.

Sign in to join this conversation.