Start: createServerFn in beforeLoad returns undefined during dev SPA navigation despite valid serverFn response
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?
Start
Describe the bug
A createServerFn called from root route beforeLoad returns undefined during client-side navigation in Vite dev.
The same server function works during SSR, and a direct fetch to the generated server function URL returns 200 with a serialized result.
Repro output:
[serverFn beforeLoad repro] {
environment: 'server',
auth: { userId: 'user_mock_repro', token: 'token_mock_repro' }
}
[serverFn beforeLoad repro] {
environment: 'browser',
auth: 'undefined'
}
[serverFn beforeLoad repro] raw serverFn fetch {
status: 200,
ok: true,
serialized: 'true',
hasSerializedResult: true,
hasUserId: true,
hasToken: true
}
Complete minimal reproducer
https://github.com/TomoFromEarth/tanstack-start-clerk-beforeload-repro
Steps to Reproduce the Bug
- Clone the repo:
git clone https://github.com/TomoFromEarth/tanstack-start-clerk-beforeload-repro.git
cd tanstack-start-clerk-beforeload-repro
- Install and run:
pnpm install
pnpm dev
-
Open
http://localhost:3000. -
Click between
HomeandRepro. -
Observe the browser console/dev server logs. During browser-side navigation,
fetchAuth()returnsundefined, then the raw fetch to the same server function URL returns200with a serialized result.
Expected behavior
Expected: await fetchAuth() returns the server function result during client navigation.
Actual: await fetchAuth() returns undefined, while the underlying endpoint returns the expected serialized payload.
Screenshots or Videos
No response
Platform
- Router / Start Version: @tanstack/react-router 1.170.16 / @tanstack/react-start 1.168.26
- OS: macOS 26.3.1
- Browser: Chrome
- Browser Version: 149.0.7827.197 (Official Build) (arm64)
- Bundler: Vite
- Bundler Version: 7.3.2
Additional context
A hard refresh/direct load of the route works because beforeLoad runs through the SSR path and receives the server function result.
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
Start with the linked minimal reproducer, run pnpm install and pnpm dev, then inspect the root route beforeLoad flow around createServerFn and fetchAuth(). Compare client-side navigation with the working SSR path and the raw server-function fetch; done means await fetchAuth() returns the serialized server-function result during browser navigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100