[feat]: Add stable IDs for server functions #7693
main fromstable-serverfn-ids-2·opened Summary by CodeRabbit#
- New Features
- Added optional support for manually providing a custom
idwhen creating server functions for stable identifier-based runtime lookup, including through chaining and locally named re-exports.
- Added optional support for manually providing a custom
- Bug Fixes
- Improved server-function ID reservation, deduping, and lifecycle across recompilations (including HMR) to prevent stale/duplicate IDs.
- Detects and rejects computed or non-statically analyzable
idshapes, and enforces collision rules for manual/manual and manual/generated cases.
- Documentation
- Added a guide for manual server function IDs, including collision behavior and security caveats.
- Tests
- Expanded type-level and compiler/runtime coverage for manual IDs, collisions, and invalidation/reuse behavior.
- 1
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 f4b60a3846160437b493772fb3a0a210b1ad7dce
Command Status Duration Result nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 26s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-24 21:56:03UTC🚀 Changeset Version Preview#
2 package(s) bumped directly, 12 bumped as dependents.
🟨 Minor bumps#
Package Version Reason @tanstack/start-client-core1.170.39 → 1.171.0 Changeset @tanstack/start-plugin-core1.171.55 → 1.172.0 Changeset 🟩 Patch bumps#
Package Version Reason @tanstack/react-start1.169.4 → 1.169.5 Dependent @tanstack/react-start-client1.168.44 → 1.168.45 Dependent @tanstack/react-start-rsc0.1.65 → 0.1.66 Dependent @tanstack/react-start-server1.167.52 → 1.167.53 Dependent @tanstack/solid-start1.169.4 → 1.169.5 Dependent @tanstack/solid-start-client1.168.42 → 1.168.43 Dependent @tanstack/solid-start-server1.167.50 → 1.167.51 Dependent @tanstack/start-server-core1.169.45 → 1.169.46 Dependent @tanstack/start-static-server-functions1.167.44 → 1.167.45 Dependent @tanstack/vue-start1.169.4 → 1.169.5 Dependent @tanstack/vue-start-client1.167.45 → 1.167.46 Dependent @tanstack/vue-start-server1.167.50 → 1.167.51 Dependent Bundle Size Benchmarks#
This pull request does not affect bundle size in any measured scenario.
More templates
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsbuild
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-next-migration
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@7693@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7693@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7693@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@7693@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@7693@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@7693@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7693@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@7693@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@7693@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@7693@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@7693@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@7693@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@7693@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@7693@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@7693@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@7693@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@7693@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7693@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@7693@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7693@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@7693@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7693@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7693@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@7693@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@7693@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@7693@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@7693@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7693@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@7693@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@7693@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7693@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@7693@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@7693@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7693@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@7693@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7693@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7693@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@7693@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@7693@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@7693@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@7693commit:
f4b60a3Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@packages/start-plugin-core/src/start-compiler/compiler.ts`: - Around line 674-689: The reserveFunctionId logic currently only checks reserved/generated IDs and manual owners, so a manual server function ID can still collide with a known server function discovered by getKnownServerFns(). Update reserveFunctionId in compiler.ts to also consult the known server-function set before accepting opts.functionId, and reject any manual ID that matches an existing server function ID so handleCreateServerFn never reuses an unrelated knownFns entry. In `@packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts`: - Around line 184-215: Resolve static template-literal IDs in the createServerFn ID extraction path: handle no-expression template literals the same way as string literals so `resolveStaticString`-compatible values like `id: \`get-user\`` and `const id = \`get-user\`; createServerFn({ id })` don’t fall through to the generic error. Update the ID resolution logic in `handleCreateServerFn` (especially the branches that currently check `t.isStringLiteral`, `t.isIdentifier`, and `bindingInit`) to accept the static template-literal case and still validate it against `MANUAL_SERVER_FN_ID_PATTERN` before returning the resolved value. - Around line 227-250: The helper getCreateServerFnCallExpression only matches an innermost callee named createServerFn, so aliased or namespace-resolved factory calls are missed and manual ids are skipped. Update the resolution logic in getCreateServerFnCallExpression (and any related createServerFn candidate handling in handleCreateServerFn.ts) to unwrap aliased/namespace call chains and recognize the actual factory call regardless of local import name, so { id: "..." } is preserved instead of falling back to generated IDs.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
01e9cb30-43da-4380-bb1e-cd0ea1f81bcd📥 Commits
Reviewing files that changed from the base of the PR and between 3d86aee2640c58a045d0946e717e282b66608e1d and a8a2739a81b7e7c85590e8df8a347f08c53b961f.
📒 Files selected for processing (6)
packages/start-client-core/src/createServerFn.tspackages/start-client-core/src/tests/createServerFn.test-d.tspackages/start-plugin-core/src/start-compiler/compiler.tspackages/start-plugin-core/src/start-compiler/handleCreateServerFn.tspackages/start-plugin-core/src/start-compiler/types.tspackages/start-plugin-core/tests/createServerFn/createServerFn.test.ts
@@ -672,3 +671,19 @@672671 return functionId673672 }674673674+ private reserveFunctionId(opts: {675+ filename: string676+ functionName: string677+ extractedFilename: string678+ functionId: string679+ }) {680+ const entryId = `${opts.filename}--${opts.functionName}`681+ const existingOwner = this.reservedManualFunctionIdOwners.get(opts.functionId)682+683+ if (existingOwner && existingOwner !== entryId) {684+ throw new Error(`Duplicate server function id: ${opts.functionId}`)685+ }686+687+ if (!existingOwner && this.functionIds.has(opts.functionId)) {688+ throw new Error(`Duplicate server function id: ${opts.functionId}`)689+ }🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject manual IDs that collide with known server functions.
reserveFunctionIdchecks this compiler’s generated/reserved IDs, but notgetKnownServerFns(). A server-only manual ID can reuse a client-discovered ID, andhandleCreateServerFnwill then treat that unrelatedknownFns[functionId]as canonical.Proposed fix
private reserveFunctionId(opts: { filename: string functionName: string extractedFilename: string functionId: string }) { const entryId = `${opts.filename}--${opts.functionName}` const existingOwner = this.reservedManualFunctionIdOwners.get(opts.functionId) + const knownFn = this.options.getKnownServerFns()[opts.functionId] + + if ( + knownFn && + (knownFn.functionName !== opts.functionName || + knownFn.extractedFilename !== opts.extractedFilename) + ) { + throw new Error(`Duplicate server function id: ${opts.functionId}`) + } if (existingOwner && existingOwner !== entryId) { throw new Error(`Duplicate server function id: ${opts.functionId}`) }📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private reserveFunctionId(opts: { filename: string functionName: string extractedFilename: string functionId: string }) { const entryId = `${opts.filename}--${opts.functionName}` const existingOwner = this.reservedManualFunctionIdOwners.get(opts.functionId) const knownFn = this.options.getKnownServerFns()[opts.functionId] if ( knownFn && (knownFn.functionName !== opts.functionName || knownFn.extractedFilename !== opts.extractedFilename) ) { throw new Error(`Duplicate server function id: ${opts.functionId}`) } if (existingOwner && existingOwner !== entryId) { throw new Error(`Duplicate server function id: ${opts.functionId}`) } if (!existingOwner && this.functionIds.has(opts.functionId)) { throw new Error(`Duplicate server function id: ${opts.functionId}`) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/start-plugin-core/src/start-compiler/compiler.ts` around lines 674 - 689, The reserveFunctionId logic currently only checks reserved/generated IDs and manual owners, so a manual server function ID can still collide with a known server function discovered by getKnownServerFns(). Update reserveFunctionId in compiler.ts to also consult the known server-function set before accepting opts.functionId, and reject any manual ID that matches an existing server function ID so handleCreateServerFn never reuses an unrelated knownFns entry.✅ Addressed in commits e81f6d6 to 20c9157
@@ -141,0 +195,21 @@195+196+ if (t.isIdentifier(prop.value)) {197+ const binding = candidatePath.scope.getBinding(prop.value.name)198+ const bindingPath = binding?.path199+ const bindingInit =200+ bindingPath && bindingPath.isVariableDeclarator()201+ ? bindingPath.node.init202+ : undefined203+204+ if (binding?.constant && bindingInit && t.isStringLiteral(bindingInit)) {205+ if (!MANUAL_SERVER_FN_ID_PATTERN.test(bindingInit.value)) {206+ throw codeFrameError(207+ code,208+ bindingInit.loc!,209+ 'createServerFn({ id }) must use a URL-safe id: [a-zA-Z0-9_-]+',210+ )211+ }212+213+ return bindingInit.value214+ }215+ }🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Resolve static template-literal ID values too.
resolveStaticStringalready handles no-expression template literals, butid: \get-user`andconst id = `get-user`; createServerFn({ id })` currently fall through to the generic error path.Proposed fix
- if (t.isStringLiteral(prop.value)) { - if (!MANUAL_SERVER_FN_ID_PATTERN.test(prop.value.value)) { + if (t.isExpression(prop.value)) { + const idValue = resolveStaticString(candidatePath, prop.value) + + if (idValue !== undefined) { + if (!MANUAL_SERVER_FN_ID_PATTERN.test(idValue)) { + throw codeFrameError( + code, + prop.value.loc!, + 'createServerFn({ id }) must use a URL-safe id: [a-zA-Z0-9_-]+', + ) + } + + return idValue + } + } + + if (t.isStringLiteral(prop.value)) { + if (!MANUAL_SERVER_FN_ID_PATTERN.test(prop.value.value)) { throw codeFrameError( code, prop.value.loc!, 'createServerFn({ id }) must use a URL-safe id: [a-zA-Z0-9_-]+', ) } return prop.value.value }📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (t.isExpression(prop.value)) { const idValue = resolveStaticString(candidatePath, prop.value) if (idValue !== undefined) { if (!MANUAL_SERVER_FN_ID_PATTERN.test(idValue)) { throw codeFrameError( code, prop.value.loc!, 'createServerFn({ id }) must use a URL-safe id: [a-zA-Z0-9_-]+', ) } return idValue } } if (t.isStringLiteral(prop.value)) { if (!MANUAL_SERVER_FN_ID_PATTERN.test(prop.value.value)) { throw codeFrameError( code, prop.value.loc!, 'createServerFn({ id }) must use a URL-safe id: [a-zA-Z0-9_-]+', ) } return prop.value.value }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts` around lines 184 - 215, Resolve static template-literal IDs in the createServerFn ID extraction path: handle no-expression template literals the same way as string literals so `resolveStaticString`-compatible values like `id: \`get-user\`` and `const id = \`get-user\`; createServerFn({ id })` don’t fall through to the generic error. Update the ID resolution logic in `handleCreateServerFn` (especially the branches that currently check `t.isStringLiteral`, `t.isIdentifier`, and `bindingInit`) to accept the static template-literal case and still validate it against `MANUAL_SERVER_FN_ID_PATTERN` before returning the resolved value.✅ Addressed in commits e81f6d6 to 20c9157
@@ -141,0 +230,21 @@230+ let currentCall: t.CallExpression | undefined = candidatePath.node231+232+ while (currentCall) {233+ const callee: t.CallExpression['callee'] = currentCall.callee234+ if (!t.isMemberExpression(callee)) {235+ return undefined236+ }237+238+ const innerCall: t.MemberExpression['object'] = callee.object239+ if (!t.isCallExpression(innerCall)) {240+ return undefined241+ }242+243+ if (t.isIdentifier(innerCall.callee, { name: 'createServerFn' })) {244+ return innerCall245+ }246+247+ currentCall = innerCall248+ }249+250+ return undefined🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Extract manual IDs from aliased and namespace factory calls.
This helper only recognizes an innermost callee literally named
createServerFn. Valid resolved candidates likeimport { createServerFn as csf }or namespace calls will silently ignore{ id: '...' }and fall back to generated IDs.Proposed fix
function getCreateServerFnCallExpression( candidatePath: babel.NodePath<t.CallExpression>, ): t.CallExpression | undefined { let currentCall: t.CallExpression | undefined = candidatePath.node + let sawMethodChain = false while (currentCall) { const callee: t.CallExpression['callee'] = currentCall.callee if (!t.isMemberExpression(callee)) { - return undefined + return sawMethodChain ? currentCall : undefined } const innerCall: t.MemberExpression['object'] = callee.object if (!t.isCallExpression(innerCall)) { - return undefined - } - - if (t.isIdentifier(innerCall.callee, { name: 'createServerFn' })) { - return innerCall + return sawMethodChain ? currentCall : undefined } + sawMethodChain = true currentCall = innerCall } return undefined }📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
function getCreateServerFnCallExpression( candidatePath: babel.NodePath<t.CallExpression>, ): t.CallExpression | undefined { let currentCall: t.CallExpression | undefined = candidatePath.node let sawMethodChain = false while (currentCall) { const callee: t.CallExpression['callee'] = currentCall.callee if (!t.isMemberExpression(callee)) { return sawMethodChain ? currentCall : undefined } const innerCall: t.MemberExpression['object'] = callee.object if (!t.isCallExpression(innerCall)) { return sawMethodChain ? currentCall : undefined } sawMethodChain = true currentCall = innerCall } return undefined }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts` around lines 227 - 250, The helper getCreateServerFnCallExpression only matches an innermost callee named createServerFn, so aliased or namespace-resolved factory calls are missed and manual ids are skipped. Update the resolution logic in getCreateServerFnCallExpression (and any related createServerFn candidate handling in handleCreateServerFn.ts) to unwrap aliased/namespace call chains and recognize the actual factory call regardless of local import name, so { id: "..." } is preserved instead of falling back to generated IDs.✅ Addressed in commits e81f6d6 to 20c9157
Merging this PR will not alter performance#
1 warning, 1 note
:warning: 48 benchmarks are dominated by system calls
System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.
:information_source: 20 benchmarks have no flamegraph
The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.
✅ 194untouched benchmarks⏩ 3skipped benchmarks1
Comparingstable-serverfn-ids-2(f4b60a3) withmain(6b9fe6d)[^unexpected-base]Footnotes#
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:#
We fixed two issues introduced by the PR's new tests and helper function: the
knownServerFnsfixture objects in the two new tests were missing the requiredfilenamefield from theServerFninterface, causing TypeScript compilation failures. We also tightened thecurrentCallvariable type fromt.CallExpression | undefinedtot.CallExpressionand replaced the always-truthywhile (currentCall)withfor (;;)to resolve the ESLintno-unnecessary-conditionerror in the newly addedgetCreateServerFnCallExpressionhelper.Warning
❌ We could not verify this fix.
Suggested Fix changes
diff --git a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts index cf68578d..9a58b1b2 100644 --- a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts +++ b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts @@ -159,20 +159,20 @@ function extractManualServerFnId( continue } - if (prop.computed) { - const keyValue = resolveStaticString(candidatePath, prop.key) + if (prop.computed) { + const keyValue = resolveStaticString(candidatePath, prop.key) - if (keyValue === 'id') { - throw codeFrameError( - code, - prop.loc!, - 'createServerFn({ [key]: value }) is not supported for manual ids.', - ) - } - - continue + if (keyValue === 'id') { + throw codeFrameError( + code, + prop.loc!, + 'createServerFn({ [key]: value }) is not supported for manual ids.', + ) } + continue + } + const isIdKey = (t.isIdentifier(prop.key) && prop.key.name === 'id') || (t.isStringLiteral(prop.key) && prop.key.value === 'id') @@ -227,9 +227,9 @@ function extractManualServerFnId( function getCreateServerFnCallExpression( candidatePath: babel.NodePath<t.CallExpression>, ): t.CallExpression | undefined { - let currentCall: t.CallExpression | undefined = candidatePath.node + let currentCall: t.CallExpression = candidatePath.node - while (currentCall) { + for (;;) { const callee: t.CallExpression['callee'] = currentCall.callee if (!t.isMemberExpression(callee)) { return undefined @@ -421,7 +421,10 @@ export function handleCreateServerFn( } functionNameSet.add(functionName) - const manualFunctionId = extractManualServerFnId(candidatePath, context.code) + const manualFunctionId = extractManualServerFnId( + candidatePath, + context.code, + ) // Generate function ID using pre-computed relative filename unless the user supplied one. const functionId = diff --git a/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts b/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts index 9e8158ea..173e8919 100644 --- a/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts +++ b/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts @@ -803,6 +803,7 @@ describe('createServerFn compiles correctly', async () => { functionId: 'constant_id', extractedFilename: '/test/src/known-fn.tsx', functionName: 'knownFn', + filename: '/test/src/known-fn.tsx', }, } @@ -841,6 +842,7 @@ describe('createServerFn compiles correctly', async () => { functionId: 'constant_id', extractedFilename: '/test/src/new-fn.tsx?tss-serverfn-split', functionName: 'greetUser_createServerFn_handler', + filename: '/test/src/new-fn.tsx', }, } @@ -942,9 +944,9 @@ describe('createServerFn compiles correctly', async () => { }) expect(firstResult!.code).toContain('createSsrRpc("get-user")') - expect(compiler.invalidateModule('/test/src/submit-post-formdata.tsx')).toBe( - true, - ) + expect( + compiler.invalidateModule('/test/src/submit-post-formdata.tsx'), + ).toBe(true) const secondResult = await compiler.compile({ code: source,
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally ox9A-RVf8
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)github-actions[bot](GitHub profile, opens in a new tab) added labelsdocumentation
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:#
We fix two type-level errors introduced by the new manual server function ID feature. A
t.isExpression()guard is added before passingprop.valuetoresolveStaticString, resolving a TS2345 mismatch where Babel'sObjectProperty.valuecan includePatternLikenodes not accepted by the function'sExpression | PrivateNamesignature. The always-truthywhile (currentCall)loop condition is replaced withwhile (true), resolving the@typescript-eslint/no-unnecessary-conditionESLint error sincecurrentCallis always a non-nullablet.CallExpressionand all loop exits are via explicitreturnstatements.Note
⏳ We are verifying this fix by re-running a subset of the 3 failed tasks that were analyzed.
diff --git a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts index db6074db..11cf876d 100644 --- a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts +++ b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts @@ -181,7 +181,9 @@ function extractManualServerFnId( continue } - const idValue = resolveStaticString(candidatePath, prop.value) + const idValue = t.isExpression(prop.value) + ? resolveStaticString(candidatePath, prop.value) + : undefined if (idValue !== undefined) { if (!MANUAL_SERVER_FN_ID_PATTERN.test(idValue)) { @@ -211,7 +213,7 @@ function getCreateServerFnCallExpression( let currentCall: t.CallExpression | undefined = candidatePath.node let sawMethodChain = false - while (currentCall) { + while (true) { const callee: t.CallExpression['callee'] = currentCall.callee if (!t.isMemberExpression(callee)) { return sawMethodChain ? currentCall : undefined
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally NZeR-Henn
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:#
We updated
getCreateServerFnCallExpressioninhandleCreateServerFn.tsto replace thewhile (currentCall)loop condition withwhile (true), which fixes the@typescript-eslint/no-unnecessary-conditionESLint error. SincecurrentCallis initialized to a non-optionalt.CallExpressionand is only ever reassigned after at.isCallExpression()guard, TypeScript correctly determines it can never be falsy, making the original condition redundant. The loop already exits exclusively viareturnstatements, sowhile (true)is semantically identical and satisfies the lint rule.Warning
❌ We could not verify this fix.
diff --git a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts index 0d0bbb8a..be702e40 100644 --- a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts +++ b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts @@ -219,7 +219,7 @@ function getCreateServerFnCallExpression( let currentCall: t.CallExpression | undefined = candidatePath.node let sawMethodChain = false - while (currentCall) { + while (true) { const callee: t.CallExpression['callee'] = currentCall.callee if (!t.isMemberExpression(callee)) { return sawMethodChain ? currentCall : undefined
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally bYpJ-ovcX
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:#
We fixed the ESLint
@typescript-eslint/no-unnecessary-conditionerror by correcting the type and loop condition in the newly addedgetCreateServerFnCallExpressionfunction. ThecurrentCallvariable was typed ast.CallExpression | undefineddespite never being assignedundefined, and thewhile (currentCall)guard was therefore always truthy. Changing the type tot.CallExpressionand the loop towhile (true)accurately reflects the logic, where all exit paths are via explicitreturnstatements.Tip
✅ We verified this fix by re-running
@tanstack/start-plugin-core:test:eslint.diff --git a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts index 0d0bbb8a..e587a47e 100644 --- a/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts +++ b/packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts @@ -216,10 +216,10 @@ function extractManualServerFnId( function getCreateServerFnCallExpression( candidatePath: babel.NodePath<t.CallExpression>, ): t.CallExpression | undefined { - let currentCall: t.CallExpression | undefined = candidatePath.node + let currentCall: t.CallExpression = candidatePath.node let sawMethodChain = false - while (currentCall) { + for (;;) { const callee: t.CallExpression['callee'] = currentCall.callee if (!t.isMemberExpression(callee)) { return sawMethodChain ? currentCall : undefined @@ -237,8 +237,6 @@ function getCreateServerFnCallExpression( sawMethodChain = true currentCall = innerCall } - - return undefined } function resolveStaticString(
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally TbLk-kNAH
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:#
We reordered the imports in
hydrateStart.tsto satisfy theimport/orderESLint rule, which requires sibling and type imports to appear before the#tanstack-*virtual module imports. The three offending imports (./ServerFunctionSerializationAdapter,@tanstack/router-coretype, and../createStarttype) were placed after the#tanstack-start-entryblock, causing the lint task to fail. Moving them above the virtual module imports resolves all three reported errors.Warning
❌ We could not verify this fix.
diff --git a/packages/start-client-core/src/client/hydrateStart.ts b/packages/start-client-core/src/client/hydrateStart.ts index 83b9c468..0f970cb9 100644 --- a/packages/start-client-core/src/client/hydrateStart.ts +++ b/packages/start-client-core/src/client/hydrateStart.ts @@ -1,13 +1,13 @@ import { hydrate } from '@tanstack/router-core/ssr/client' +import { ServerFunctionSerializationAdapter } from './ServerFunctionSerializationAdapter' +import type { AnyRouter, AnySerializationAdapter } from '@tanstack/router-core' +import type { AnyStartInstanceOptions } from '../createStart' import { startInstance } from '#tanstack-start-entry' import { hasPluginAdapters, pluginSerializationAdapters, } from '#tanstack-start-plugin-adapters' import { getRouter } from '#tanstack-router-entry' -import { ServerFunctionSerializationAdapter } from './ServerFunctionSerializationAdapter' -import type { AnyRouter, AnySerializationAdapter } from '@tanstack/router-core' -import type { AnyStartInstanceOptions } from '../createStart' type HotContext = { data?: Record<string, unknown>🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally gmHD-TZ65
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:#
We classified this build failure as an environment issue rather than a code change. The error is a
nitro/nitro-nightlypackage version mismatch wherenitro-nightlytries to import an unexported subpath (./runtime/meta) — this occurs during Vite config loading, before any of our PR's compiler code is executed. Our PR makes no changes to dependency files, and the failing example project is not among the projects touched by this PR.No code changes were suggested for this issue.
Trigger a rerun:
View detailed reasoning on Nx Cloud ↗
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:#
We investigated the three failing tasks and determined none are caused by this PR's changes. The failures stem from pre-existing environment issues: stale build artifacts in a dist directory, a hardcoded port conflict between two Vue e2e services, and an incompatible nitro-nightly package that doesn't export the required subpath. All failing projects are outside the scope of our touched projects, so no code changes are needed.
No code changes were suggested for this issue.
Trigger a rerun:
View detailed reasoning on Nx Cloud ↗
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Nx Cloud has identified a flaky task in your failed CI:#
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
View detailed reasoning in Nx Cloud ↗
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:#
We traced the failing test back to an unrelated part of the codebase and don't believe this PR caused it. The
navigate() with href containing basepathtest times out on client-side router navigation logic, while this PR only touches server function ID generation instart-client-coreandstart-plugin-core's babel compiler. Given the 0% flakiness rate rules out a simple flaky rerun, we're classifying this as a pre-existing environment issue rather than something introduced here.No code changes were suggested for this issue.
Trigger a rerun:
View detailed reasoning on Nx Cloud ↗
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Nx Cloud has identified a flaky task in your failed CI:#
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
View detailed reasoning in Nx Cloud ↗
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)Nx Cloud has identified a flaky task in your failed CI:#
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
View detailed reasoning in Nx Cloud ↗
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)🦋 Changeset detected#
Latest commit: f4b60a3846160437b493772fb3a0a210b1ad7dce
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 14 packages
Name Type @tanstack/start-client-core Minor @tanstack/start-plugin-core Minor @tanstack/react-start-client Patch @tanstack/react-start-rsc Patch @tanstack/react-start Patch @tanstack/solid-start-client Patch @tanstack/solid-start Patch @tanstack/start-server-core Patch @tanstack/start-static-server-functions Patch @tanstack/vue-start-client Patch @tanstack/vue-start Patch @tanstack/react-start-server Patch @tanstack/solid-start-server Patch @tanstack/vue-start-server Patch Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
Walkthrough
This PR adds optional
idsupport tocreateServerFnand threads explicit server-function IDs through compiler reservation, invalidation cleanup, docs, and tests.Changes#
Manual server-function ID reservation
packages/start-client-core/src/createServerFn.ts,packages/start-client-core/src/tests/createServerFn.test-d.ts,packages/start-plugin-core/src/start-compiler/types.tscreateServerFnoption types gain optionalid?: string,CompilationContextgainsreserveFunctionId, and the type test asserts acreateServerFn({ id })call exposeshandler.packages/start-plugin-core/src/start-compiler/compiler.tsStartCompilertracks reserved manual IDs, updates ID generation and deduplication, clears reservations on module invalidation, and exposes the new context handler.packages/start-plugin-core/src/start-compiler/handleCreateServerFn.tshandleCreateServerFnextracts staticidoptions, validates the format, and reserves explicit IDs when present.packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts,docs/start/framework/react/guide/server-functions.mdEstimated code review effort#
🎯 4 (Complex) | ⏱️ ~60 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share