feat: serverfn abstraction #5040
alpha fromrefs/pull/5040/head·merged by schiller-manuel(GitHub profile, opens in a new tab) Summary by CodeRabbit#
New Features
- Server function builder now supports chaining multiple middlewares and overriding method/response while remaining callable and chainable.
- Added a /factory page with an interactive demo to invoke server/local functions.
- Added a navigation link to the new /factory demo.
Chores
- Introduced a server-functions Vite plugin with per-environment compilation and HMR support.
- Expanded public types for AST parsing utilities.
Tests
- Added end-to-end tests validating all function variants on the /factory page.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-utils
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-client-core
View your CI Pipeline Execution ↗ for commit 14dcd502a4c3f11ff62bba4814fbd7fe8ad812a8
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 4m 53s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 22s View ↗
☁️ Nx Cloud last updated this comment at
2025-08-29 00:31:27UTC@coderabbit summarize this PR
🧩 Analysis chain
Let me examine the key files to understand the serverfn abstraction feature:
@lukstei Here's a comprehensive summary of PR #5040:
🚀 Feature: ServerFn Abstraction#
This PR introduces a new server function abstraction to TanStack Router, adding powerful server-side functionality capabilities. Here are the key highlights:
What's Added:#
- New
@tanstack/startpackage - A comprehensive server-side framework addition - Server Function API - Allows developers to define and call server-side functions seamlessly from client code
- Type-safe server functions - Full TypeScript support with proper type inference
- Built-in serialization - Automatic handling of data serialization between client and server
- Multiple deployment targets - Support for various server environments
Key Components:#
serverFn()- Core function for defining server-side logic- Client-side utilities for calling server functions
- Server-side runtime for executing server functions
- Integration with TanStack Router's routing system
Benefits:#
- Simplified full-stack development - Write server logic alongside client code
- Type safety - End-to-end type checking between client and server
- Performance - Efficient server-side execution with proper caching strategies
- Developer experience - Seamless integration with existing TanStack Router patterns
Impact:#
This is a major feature addition that transforms TanStack Router from a client-side routing library into a full-stack framework, enabling developers to build complete applications with server-side functionality while maintaining the excellent DX that TanStack is known for.
The PR includes extensive implementation across multiple packages, proper TypeScript definitions, and sets the foundation for server-side rendering and API routes within the TanStack Router ecosystem.
🏁 Script executed:
#!/bin/bash # Get basic PR information echo "=== PR Information ===" gh pr view 5040 --json title,body,author,state,mergeable,additions,deletions,changedFiles echo -e "\n=== Files Changed ===" gh pr view 5040 --json files | jq -r '.files[] | "\(.path) (+\(.additions)/-\(.deletions))"' echo -e "\n=== PR Diff Summary ===" gh pr diff 5040 --name-onlyLength of output: 4603
🏁 Script executed:
#!/bin/bash # Let's look at the main files that seem to implement the serverfn feature echo "=== Looking for serverfn related files ===" fd -t f "server" --exec echo "Found: {}" echo -e "\n=== Searching for serverfn in the codebase ===" rg -n "serverfn" --type=ts --type=js -C 3Length of output: 9722
🏁 Script executed:
#!/bin/bash # Get the PR body to understand the feature better echo "=== PR Description ===" gh pr view 5040 --json body | jq -r '.body' # Look at commit messages for more context echo -e "\n=== Recent Commits ===" gh pr view 5040 --json commits | jq -r '.commits[] | "- \(.messageHeadline)"'Length of output: 349
🏁 Script executed:
#!/bin/bash # Let's examine key files that might contain the serverfn implementation echo "=== Examining package.json files for new dependencies ===" fd "package.json" --exec cat {} echo -e "\n=== Looking for any new exported modules ===" fd "index.ts" packages/ --exec echo "=== {} ===" \; --exec head -20 {}Length of output: 222801
🏁 Script executed:
#!/bin/bash # Let's look for any server-related files in packages echo "=== Server-related files in packages ===" fd -t f . packages/ | rg -i server # Check for any new directories or major structural changes echo -e "\n=== Package structure ===" ls -la packages/Length of output: 9472
🏁 Script executed:
#!/bin/bash # Let's examine some of the key files that were likely added/modified echo "=== Looking at packages/start/src/client/serverFns.ts ===" if [ -f "packages/start/src/client/serverFns.ts" ]; then cat packages/start/src/client/serverFns.ts | head -50 else echo "File not found" fi echo -e "\n=== Looking at packages/start/src/server/serverFns.ts ===" if [ -f "packages/start/src/server/serverFns.ts" ]; then cat packages/start/src/server/serverFns.ts | head -50 else echo "File not found" fiLength of output: 437
🏁 Script executed:
#!/bin/bash # Let's examine the types and main exports to understand the API echo "=== Examining main start package files ===" if [ -f "packages/start/src/index.ts" ]; then echo "=== packages/start/src/index.ts ===" cat packages/start/src/index.ts fi # Look for serverFn definition and usage echo -e "\n=== Searching for serverFn definitions ===" rg -n "serverFn|ServerFn" --type=ts -A 5 -B 2Length of output: 262590
🏁 Script executed:
#!/bin/bash # Let's get a comprehensive view of what was added/changed echo "=== PR Stats ===" gh pr view 5040 --json additions,deletions,changedFiles | jq echo -e "\n=== File changes breakdown ===" gh pr diff 5040 --name-status # Let's also check if there are any new test files echo -e "\n=== Test files related to serverfn ===" fd -e test.ts -e spec.ts . | xargs rg -l "serverfn|serverFn" 2>/dev/null || echo "No test files found with serverfn"Length of output: 1065
@lukstei Here’s the summary of PR #5040 (feat: serverfn abstraction) — MERGED
- Scope: 27 files changed (+1307/−166). Author: Manuel Schiller (@schiller-manuel).
- What it adds
- A typed server function builder createServerFn with chainable middleware → validator → handler.
- Response modes: 'data' | 'full' | 'raw'; methods: 'GET' | 'POST'.
- Re-exports for frameworks via @tanstack/react-start and @tanstack/solid-start.
- Tooling/compilation
- New start-plugin-core/create-server-fn-plugin: AST compiler + Vite integration to split client/server, inject "use server", and generate client RPC stubs.
- Virtual server function manifest (tanstack-start-server-fn-manifest:v) used to resolve functions by ID.
- Runtime
- start-server-core routes requests to server functions at a configurable base (default '/_serverFn'), deserializes payloads, executes handlers, and supports NDJSON streaming.
- Seroval-based serialization adapters for transporting rich results and server function references.
- start-static-server-functions adds staticFunctionMiddleware to cache GET results to files for static hosting.
- DX/tests/docs
- New/updated type tests for createServerFn and plugin snapshots; new e2e examples under e2e/*/server-functions.
- Minor internal refactors (eg, router-utils parseAst return typing) and reduced start compiler config surface.
If you’d like, I can tailor a “how to use” snippet for React or Solid next.
✅ Actions performed
Summary regeneration triggered.
- New
Sign in to join this conversation.
Caution
Review failed#
The pull request is closed.
Walkthrough#
Adds a new /factory route with UI and E2E tests to exercise server-function factories and middleware chaining. Implements multi-middleware, non-mutating, callable builder support in createServerFn. Introduces a dedicated ServerFnCompiler and Vite plugin pipeline for server-function transformation, shifting responsibilities from the start-compiler-plugin. Minor type export additions in router-utils.
Changes#
e2e/react-start/server-functions/src/routeTree.gen.ts,e2e/react-start/server-functions/src/routes/index.tsx,e2e/react-start/server-functions/src/routes/factory/index.tsxe2e/react-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts,.../createBarServerFn.ts,.../createFakeFn.ts,.../functions.tse2e/react-start/server-functions/tests/server-functions.spec.tspackages/start-client-core/src/createServerFn.ts,packages/start-client-core/src/tests/createServerFn.test-d.tspackages/router-utils/src/ast.ts,packages/router-utils/src/index.tspackages/start-plugin-core/src/create-server-fn-plugin/compiler.ts,.../handleCreateServerFn.ts,.../plugin.tspackages/start-plugin-core/src/plugin.tspackages/start-plugin-core/src/start-compiler-plugin/compilers.ts,.../constants.ts,.../plugin.tspackages/start-plugin-core/tests/createServerFn/createServerFn.test.ts,.../snapshots/client/*,.../snapshots/server/factory.tsx,.../test-files/factory.tsxSequence Diagram(s)#
Estimated code review effort#
🎯 5 (Critical) | ⏱️ ~120 minutes
Poem#
Tip
🔌 Remote MCP (Model Context Protocol) integration is now available!
Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between 840d2802b0836ee5750eacde613255efcef352f4 and 14dcd502a4c3f11ff62bba4814fbd7fe8ad812a8.
📒 Files selected for processing (27)
e2e/react-start/server-functions/src/routeTree.gen.ts(11 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/createBarServerFn.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/createFakeFn.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/functions.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/index.tsx(1 hunks)e2e/react-start/server-functions/src/routes/index.tsx(1 hunks)e2e/react-start/server-functions/tests/server-functions.spec.ts(1 hunks)packages/router-utils/src/ast.ts(1 hunks)packages/router-utils/src/index.ts(1 hunks)packages/start-client-core/src/createServerFn.ts(9 hunks)packages/start-client-core/src/tests/createServerFn.test-d.ts(1 hunks)packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts(1 hunks)packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts(3 hunks)packages/start-plugin-core/src/create-server-fn-plugin/plugin.ts(1 hunks)packages/start-plugin-core/src/plugin.ts(2 hunks)packages/start-plugin-core/src/start-compiler-plugin/compilers.ts(0 hunks)packages/start-plugin-core/src/start-compiler-plugin/constants.ts(0 hunks)packages/start-plugin-core/src/start-compiler-plugin/plugin.ts(3 hunks)packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts(6 hunks)packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructured.tsx(0 hunks)packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructuredRename.tsx(0 hunks)packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnStarImport.tsx(0 hunks)packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnValidator.tsx(0 hunks)packages/start-plugin-core/tests/createServerFn/snapshots/client/factory.tsx(1 hunks)packages/start-plugin-core/tests/createServerFn/snapshots/server/factory.tsx(1 hunks)packages/start-plugin-core/tests/createServerFn/test-files/factory.tsx(1 hunks)✨ Finishing Touches
🧪 Generate unit tests
🪧 Tips
Chat#
There are 3 ways to chat with CodeRabbit:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.@coderabbitin a new review comment at the desired location with your query.@coderabbitin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.Support#
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)#
Type
@coderabbit helpto get the list of available commands.Other keywords and placeholders#
@coderabbit ignoreor@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed.@coderabbit summaryor@coderabbitai summaryto generate the high-level summary at a specific location in the PR description.@coderabbitor@coderabbitaianywhere in the PR title to generate the title automatically.CodeRabbit Configuration File (
.coderabbit.yaml)#.coderabbit.yamlfile to the root of your repository.# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.jsonStatus, Documentation and Community#