Skip to content
Source
Sign inSign up
TanStack/router

[feat]: Add stable IDs for server functions #7693

OpenLadyBluenotes(GitHub profile, opens in a new tab)wants to merge 30 commits intomain fromstable-serverfn-ids-2opened

Showing 13 changed files with 106 additions and 0 deletions (loading 9).

x
0 of 13 viewed, 13 left
6 additions and 0 deletions.changeset/sour-dancers-buy.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/start-client-core': minor
+'@tanstack/start-plugin-core': minor
+---
+​
+Add support for stable, manually assigned server function IDs.
69 additions and 0 deletionsdocs/start/framework/react/guide/server-functions.mdModified
View file
@@ -157,6 +157,75 @@
> const { getUser } = await import('~/utils/users.functions')
> ```
​
+## Manual Server Function IDs
+​
+By default, TanStack Start generates a function ID for each server function. You can optionally provide a manual ID when you want a stable, explicit identifier under your control.
+​
+Use manual IDs when you need predictable identifiers across refactors, clearer diagnostics, or explicit naming conventions.
+​
+```tsx
+import { createServerFn } from '@tanstack/react-start'
+​
+export const getUser = createServerFn({ method: 'GET', id: 'get-user' })
+ .validator((data: { userId: string }) => data)
+ .handler(async ({ data }) => {
+ return findUserById(data.userId)
+ })
+```
+​
+### Rules for Manual IDs