[Start] virtual:tanstack-start-client-entry 404 in pnpm monorepo (regression on react-start@1.168 + vite@8) #7418
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→ resolvesstart-plugin-core@1.170.0,start-server-core@1.168.0,start-client-core@1.169.0pnpm-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):
| URL | Status |
|---|---|
/@id/virtual:tanstack-start-client-entry | 404 |
/@id/__x00__virtual:tanstack-start-client-entry | 200 |
/@id/%00virtual:tanstack-start-client-entry | 200 |
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 */],
})
Related#
please provide a minimal complete reproducer project
schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed
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 devSSR 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 -> 200Pinned to
@tanstack/react-start@1.168.0+vite@8.0.13, pnpm 11 withenableGlobalVirtualStore: true(resolves tostart-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.Also have this happening on my end, but it doesn't always happen which is strange. Workaround didn't work on my pnpm monorepo :/
any temporary fixes?
Sign in to join this conversation.
Drafted a candidate fix —
gh pr createfrom 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:ArthurSaenz/router @ fix/start-vite8-virtual-entry-urlChanges (3 files)#
packages/start-plugin-core/src/vite/dev-server-plugin/extract-html-scripts.ts— normalize bare/@id/virtual:*→/@id/__x00__virtual:*onsrcand inlinecontentat the extraction boundarypackages/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—patchfor@tanstack/start-plugin-corepnpm 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.