Static middleware entries are not routed to on production builds
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Router
Describe the bug
Repro: https://github.com/arackaf/tanstack-blog-blog-post
npm run build
npm start
root page should render. Click on a blog post - page will error.
This fetch
http://localhost:3000/__tsr/staticServerFnCache/e43004e6c38437f0d2f24def37e3af0e555c9e94.json
404's. Here's AI's take:
You've found a real build-order bug, not a missing dependency. The cache files exist on disk; the Nitro production server just doesn't know about them.
Root cause: build order
The __tsr/staticServerFnCache/*.json files are created after Nitro bakes the static asset manifest into the server bundle.
Flow:
Nitro builds .output/server/index.mjs and scans .output/public/ into a hardcoded assets map.
TanStack prerender runs later (via staticFunctionMiddleware during prerender) and writes cache files to .output/public/__tsr/staticServerFnCache/.
The cache files are written 3 seconds after the server bundle is finalized.
Both plugins use buildApp: { order: "post" }, but Nitro's hook runs before TanStack's post-build prerender. So the manifest is frozen before __tsr exists.
Complete minimal reproducer
https://github.com/arackaf/tanstack-blog-blog-post
Steps to Reproduce the Bug
See above
Expected behavior
Should work :)
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.168.6
- OS: macOS
- Browser: Chrome
- Browser Version: 148
- Bundler: Vite
- Bundler Version: 7.1.7
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure in the linked tanstack-blog-blog-post example with npm run build followed by npm start, then trace staticFunctionMiddleware and Nitro's production asset handling around __tsr/staticServerFnCache. Done means clicking a blog post in the production build loads successfully and the referenced cache JSON no longer returns 404.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100