TanStack / TanStack/router

Crash "TypeError: serverFn is not a function" when calling server function with nested server function multiple times

Open
#6,451 6 comments 7 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

Which project does this relate to?

Start

Describe the bug

Sometimes TanStack Start crashes on this line with the following error when calling a specific server function multiple times at nearly the same time:

    return serverFn(...args)
           ^

TypeError: serverFn is not a function
    at Object.fn (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-server-core/src/createSsrRpc.ts:18:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async client (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-client-core/src/createServerFn.ts:786:21)
    at async callNextMiddleware (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-client-core/src/createServerFn.ts:282:24)
    at async Object.assign (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-client-core/src/createServerFn.ts:120:26)
Your Example Website or App

https://github.com/ulrichstark/tanstack-repro-crash-serverfn-is-not-a-function

Steps to Reproduce the Bug or Issue
git clone https://github.com/ulrichstark/tanstack-repro-crash-serverfn-is-not-a-function
cd tanstack-repro-crash-serverfn-is-not-a-function
npm i
npx vite
Expected behavior

Don't crash

Screenshots or Videos

No response

Platform
  • Router / Start Version: 1.154.7
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 143.0.7499.170
  • Bundler: Vite
  • Bundler Version: 7.3.1
Additional context

Clicking the button in my repro calls the server function uploadDocumentServerFn 100 times. This server function calls the imported server function analyzeDocumentServerFn. And this server function uses and imports getCookies from @tanstack/react-start and zodTextFormat from openai.

Sometimes the button doesn't trigger the crash, so just click it again until the dev server crashes.

I don't think I'm able to remove more stuff from my repro project while still getting the dev server to crash on button click. I also noticed that when removing the @tailwindcss/vite plugin from vite.config.ts, the crash goes away.

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 crash with the linked app using npm i and npx vite, then inspect packages/start-server-core/src/createSsrRpc.ts at line 18 and the related createServerFn.ts stack frames. Compare behavior with and without the @tailwindcss/vite plugin and repeated concurrent calls to uploadDocumentServerFn. Done means the server no longer crashes under the reproduction steps.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.