TanStack / TanStack/router

staticFunctionMiddleware does not respect basePath configuration

Open
#6,152 3 comments 3 reactions 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

Discussed in https://github.com/TanStack/router/discussions/6146

Originally posted by busy-dog December 19, 2025

Description of the Issue

staticFunctionMiddleware defaults to mounting __tsr/staticServerFnCache at the root path /__tsr/...
Even if base or basePath is set in SSR or Router configuration, the URLs generated by the middleware still access from the root path, leading to 404 errors when accessing resources.

Reproduction Steps

Configure vite.config.ts, set base: '/docs/', and deploy to Ng with corresponding resource routing configured.
Open the browser and navigate to any route. The chromedevtools network shows /__tsr/staticServerFnCache/xxx.json 404.

Expected behavior
The actual request should be to /docs/__tsr/staticServerFnCache/xxx.json

Possible Solution

Add a parameter to the getStaticCacheUrl method in the staticFunctionMiddleware.ts file of start-static-server-functions, or try reading the basePath to correct the fetch url

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

Start in the staticFunctionMiddleware.ts file of start-static-server-functions, especially getStaticCacheUrl, and review the base setting in vite.config.ts. Reproduce with base set to /docs/ and inspect the generated staticServerFnCache request. Done means the request uses /docs/__tsr/staticServerFnCache/... instead of the root path and no longer returns a 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
full-stack, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.