Skip to content
Source
Sign inSign up
TanStack/router

[Start] virtual:tanstack-start-client-entry 404 in pnpm monorepo (regression on react-start@1.168 + vite@8) #7418

OpenArthurSaenz(GitHub profile, opens in a new tab) opened this issue 5 comments

Which project does this relate to?

Start

Bug

On a fresh install with @tanstack/react-start@1.168.0 + vite@8.0.13 in a pnpm monorepo (enableGlobalVirtualStore: true), every dev request to:

GET /@id/virtual:tanstack-start-client-entry

returns 404. Hydration fails (Uncaught (in promise) TypeError: Failed to fetch dynamically imported module) and the routed <Outlet /> renders empty — header and footer from the pathless layout show, the page body is blank.

This is the exact symptom of #6588 (closed, "fixed in v1.159.6" via #7178), so I'm filing this as a regression rather than commenting on the closed thread.

Repro

  • pnpm 11.x, Node 24.x, macOS
  • vite@8.0.13
  • @tanstack/react-start@1.168.0 → resolves start-plugin-core@1.170.0, start-server-core@1.168.0, start-client-core@1.169.0
  • pnpm-workspace.yaml: enableGlobalVirtualStore: true
  • Start the Vite dev server, open / in any browser

SSR HTML emits:

import("/@id/virtual:tanstack-start-client-entry")

Diagnosis

In Vite 8 the /@id/ middleware requires virtual-module URLs to carry the null-byte prefix encoded as __x00__ (or %00):

URLStatus
/@id/virtual:tanstack-start-client-entry404
/@id/__x00__virtual:tanstack-start-client-entry200
/@id/%00virtual:tanstack-start-client-entry200

start-plugin-core@1.170.0's createVirtualModule correctly returns the \0-prefixed resolvedId from its resolveId hook, but the SSR-emitted client bootstrap (from start-server-core@1.168.0) writes the bare-prefix URL into the HTML, so Vite 8's URL-to-id middleware never reaches the plugin's hook.

Workaround

Inline Vite plugin that rewrites the URL before resolution (works locally):

import { defineConfig, type Plugin } from 'vite'

const tanstackVirtualUrlShim = (): Plugin => ({
  name: 'tanstack-start:virtual-url-shim',
  enforce: 'pre',
  configureServer(server) {
    server.middlewares.use((req, _res, next) => {
      if (req.url?.startsWith('/@id/virtual:tanstack-')) {
        req.url = req.url.replace('/@id/virtual:', '/@id/__x00__virtual:')
      }
      next()
    })
  },
})

export default defineConfig({
  plugins: [tanstackVirtualUrlShim(), /* ...rest */],
})
  • Closed: #6588 (original report)
  • Closed: #7155 (reverse-proxy variant — same \0-prefix discussion)
  • Merged: #7178 (the previous fix this regressed against)
  1. Drafted a candidate fix — gh pr create from my account is being rejected with a 404/permission error (likely an SSO/org-policy thing on my token), so the PR isn't open yet. Branch is pushed to my fork and ready for review:

    Changes (3 files)

    • packages/start-plugin-core/src/vite/dev-server-plugin/extract-html-scripts.ts — normalize bare /@id/virtual:* → /@id/__x00__virtual:* on src and inline content at the extraction boundary
    • packages/start-plugin-core/tests/extract-html-scripts.test.ts — 6 cases covering normal extraction, bare→encoded rewrite (content + src), idempotency on already-encoded URLs, and non-virtual /@id/* left untouched
    • .changeset/fix-vite8-virtual-entry-url-encoding.md — patch for @tanstack/start-plugin-core

    pnpm exec vitest run extract-html-scripts → 6 pass / 0 fail.

    Happy for a maintainer to either pull this in via a PR from the branch, suggest a different fix location, or take it as a reference and write the patch in the spot they prefer.

  2. please provide a minimal complete reproducer project

  3. schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed

  4. Minimal reproducer per request:

    Repo: https://github.com/ArthurSaenz/tanstack-router-7418-repro

    git clone https://github.com/ArthurSaenz/tanstack-router-7418-repro
    cd tanstack-router-7418-repro
    pnpm install && pnpm dev

    SSR HTML emits import("/@id/virtual:tanstack-start-client-entry"), which 404s in Vite 8. Same module returns 200 when the null byte is encoded (__x00__ or %00):

    GET /@id/virtual:tanstack-start-client-entry          -> 404
    GET /@id/__x00__virtual:tanstack-start-client-entry   -> 200
    GET /@id/%00virtual:tanstack-start-client-entry       -> 200

    Pinned to @tanstack/react-start@1.168.0 + vite@8.0.13, pnpm 11 with enableGlobalVirtualStore: true (resolves to start-server-core@1.168.0, start-client-core@1.169.0, start-plugin-core@1.170.0). No Tailwind / devtools / server fns — just file-based routes with __root + index.

  5. Also have this happening on my end, but it doesn't always happen which is strange. Workaround didn't work on my pnpm monorepo :/

Sign in to join this conversation.