TanStack / TanStack/router

Static middleware entries are not routed to on production builds

Open
#7,479 2 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.