Skip to content
Source
Sign inSign up
TanStack/router

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

OpenTomoFromEarth(GitHub profile, opens in a new tab) opened this issue 1 comment

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.

  1. i wasnt able to reproduce this using your project.

  2. schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed

Sign in to join this conversation.