TanStack / TanStack/router

Start: createServerFn in beforeLoad returns undefined during dev SPA navigation despite valid serverFn response

Open
#7,716 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

information needed
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
  1. Clone the repo:
git clone https://github.com/TomoFromEarth/tanstack-start-clerk-beforeload-repro.git
cd tanstack-start-clerk-beforeload-repro
  1. Install and run:
pnpm install
pnpm dev
  1. Open http://localhost:3000.

  2. Click between Home and Repro.

  3. Observe the browser console/dev server logs. During browser-side navigation, fetchAuth() returns undefined, then the raw fetch to the same server function URL returns 200 with 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.