diff --git a/e2e/react-start/server-functions/src/routeTree.gen.ts b/e2e/react-start/server-functions/src/routeTree.gen.ts index f83dc9146be..eff2eb05845 100644 --- a/e2e/react-start/server-functions/src/routeTree.gen.ts +++ b/e2e/react-start/server-functions/src/routeTree.gen.ts @@ -38,6 +38,7 @@ import { Route as MiddlewareServerImportMiddlewareRouteImport } from './routes/m import { Route as MiddlewareSendServerFnRouteImport } from './routes/middleware/send-serverFn' import { Route as MiddlewareRequestMiddlewareRouteImport } from './routes/middleware/request-middleware' import { Route as MiddlewareMiddlewareFactoryRouteImport } from './routes/middleware/middleware-factory' +import { Route as MiddlewareFunctionMetadataRouteImport } from './routes/middleware/function-metadata' import { Route as MiddlewareClientMiddlewareRouterRouteImport } from './routes/middleware/client-middleware-router' import { Route as CookiesSetRouteImport } from './routes/cookies/set' import { Route as AbortSignalMethodRouteImport } from './routes/abort-signal/$method' @@ -191,6 +192,12 @@ const MiddlewareMiddlewareFactoryRoute = path: '/middleware/middleware-factory', getParentRoute: () => rootRouteImport, } as any) +const MiddlewareFunctionMetadataRoute = + MiddlewareFunctionMetadataRouteImport.update({ + id: '/middleware/function-metadata', + path: '/middleware/function-metadata', + getParentRoute: () => rootRouteImport, + } as any) const MiddlewareClientMiddlewareRouterRoute = MiddlewareClientMiddlewareRouterRouteImport.update({ id: '/middleware/client-middleware-router', @@ -233,6 +240,7 @@ export interface FileRoutesByFullPath { '/abort-signal/$method': typeof AbortSignalMethodRoute '/cookies/set': typeof CookiesSetRoute '/middleware/client-middleware-router': typeof MiddlewareClientMiddlewareRouterRoute + '/middleware/function-metadata': typeof MiddlewareFunctionMetadataRoute '/middleware/middleware-factory': typeof MiddlewareMiddlewareFactoryRoute '/middleware/request-middleware': typeof MiddlewareRequestMiddlewareRoute '/middleware/send-serverFn': typeof MiddlewareSendServerFnRoute @@ -268,6 +276,7 @@ export interface FileRoutesByTo { '/abort-signal/$method': typeof AbortSignalMethodRoute '/cookies/set': typeof CookiesSetRoute '/middleware/client-middleware-router': typeof MiddlewareClientMiddlewareRouterRoute + '/middleware/function-metadata': typeof MiddlewareFunctionMetadataRoute '/middleware/middleware-factory': typeof MiddlewareMiddlewareFactoryRoute '/middleware/request-middleware': typeof MiddlewareRequestMiddlewareRoute '/middleware/send-serverFn': typeof MiddlewareSendServerFnRoute @@ -304,6 +313,7 @@ export interface FileRoutesById { '/abort-signal/$method': typeof AbortSignalMethodRoute '/cookies/set': typeof CookiesSetRoute '/middleware/client-middleware-router': typeof MiddlewareClientMiddlewareRouterRoute + '/middleware/function-metadata': typeof MiddlewareFunctionMetadataRoute '/middleware/middleware-factory': typeof MiddlewareMiddlewareFactoryRoute '/middleware/request-middleware': typeof MiddlewareRequestMiddlewareRoute '/middleware/send-serverFn': typeof MiddlewareSendServerFnRoute @@ -341,6 +351,7 @@ export interface FileRouteTypes { | '/abort-signal/$method' | '/cookies/set' | '/middleware/client-middleware-router' + | '/middleware/function-metadata' | '/middleware/middleware-factory' | '/middleware/request-middleware' | '/middleware/send-serverFn' @@ -376,6 +387,7 @@ export interface FileRouteTypes { | '/abort-signal/$method' | '/cookies/set' | '/middleware/client-middleware-router' + | '/middleware/function-metadata' | '/middleware/middleware-factory' | '/middleware/request-middleware' | '/middleware/send-serverFn' @@ -411,6 +423,7 @@ export interface FileRouteTypes { | '/abort-signal/$method' | '/cookies/set' | '/middleware/client-middleware-router' + | '/middleware/function-metadata' | '/middleware/middleware-factory' | '/middleware/request-middleware' | '/middleware/send-serverFn' @@ -447,6 +460,7 @@ export interface RootRouteChildren { AbortSignalMethodRoute: typeof AbortSignalMethodRoute CookiesSetRoute: typeof CookiesSetRoute MiddlewareClientMiddlewareRouterRoute: typeof MiddlewareClientMiddlewareRouterRoute + MiddlewareFunctionMetadataRoute: typeof MiddlewareFunctionMetadataRoute MiddlewareMiddlewareFactoryRoute: typeof MiddlewareMiddlewareFactoryRoute MiddlewareRequestMiddlewareRoute: typeof MiddlewareRequestMiddlewareRoute MiddlewareSendServerFnRoute: typeof MiddlewareSendServerFnRoute @@ -669,6 +683,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof MiddlewareMiddlewareFactoryRouteImport parentRoute: typeof rootRouteImport } + '/middleware/function-metadata': { + id: '/middleware/function-metadata' + path: '/middleware/function-metadata' + fullPath: '/middleware/function-metadata' + preLoaderRoute: typeof MiddlewareFunctionMetadataRouteImport + parentRoute: typeof rootRouteImport + } '/middleware/client-middleware-router': { id: '/middleware/client-middleware-router' path: '/middleware/client-middleware-router' @@ -719,6 +740,7 @@ const rootRouteChildren: RootRouteChildren = { AbortSignalMethodRoute: AbortSignalMethodRoute, CookiesSetRoute: CookiesSetRoute, MiddlewareClientMiddlewareRouterRoute: MiddlewareClientMiddlewareRouterRoute, + MiddlewareFunctionMetadataRoute: MiddlewareFunctionMetadataRoute, MiddlewareMiddlewareFactoryRoute: MiddlewareMiddlewareFactoryRoute, MiddlewareRequestMiddlewareRoute: MiddlewareRequestMiddlewareRoute, MiddlewareSendServerFnRoute: MiddlewareSendServerFnRoute, diff --git a/e2e/react-start/server-functions/src/routes/middleware/function-metadata.tsx b/e2e/react-start/server-functions/src/routes/middleware/function-metadata.tsx new file mode 100644 index 00000000000..e543862e91b --- /dev/null +++ b/e2e/react-start/server-functions/src/routes/middleware/function-metadata.tsx @@ -0,0 +1,164 @@ +import { createFileRoute } from '@tanstack/react-router' +import { createMiddleware, createServerFn } from '@tanstack/react-start' +import React from 'react' + +const metadataMiddleware = createMiddleware({ type: 'function' }) + .client(async ({ next, serverFnMeta }) => { + return next({ + sendContext: { + clientCapturedMeta: serverFnMeta, + }, + }) + }) + .server(async ({ next, serverFnMeta, context }) => { + return next({ + context: { + serverCapturedMeta: serverFnMeta, + clientCapturedMeta: context.clientCapturedMeta, + }, + }) + }) + +// Server function that returns both client and server captured metadata +const getMetadataFn = createServerFn() + .middleware([metadataMiddleware]) + .handler(async ({ context }) => { + return { + // Full metadata captured by server middleware + serverMeta: context.serverCapturedMeta, + // Metadata captured by client middleware and sent via sendContext + // Client middleware only has { id }, not { name, filename } + clientCapturedMeta: context.clientCapturedMeta, + } + }) + +export const Route = createFileRoute('/middleware/function-metadata')({ + loader: () => getMetadataFn(), + component: RouteComponent, +}) + +function RouteComponent() { + const loaderData = Route.useLoaderData() + + const [clientData, setClientData] = React.useState( + null, + ) + + return ( +
+

Function Metadata in Middleware

+

+ This test verifies that both client and server middleware receive + serverFnMeta in their options. Client middleware gets only the id, while + server middleware gets the full metadata (id, name, filename). +

+
+
+
+

Loader Data (SSR)

+

Server Captured Metadata:

+
+ Function ID:{' '} + + {loaderData.serverMeta?.id} + +
+
+ Function Name:{' '} + + {loaderData.serverMeta?.name} + +
+
+ Filename:{' '} + + {loaderData.serverMeta?.filename} + +
+

Client Captured Metadata (via sendContext):

+

Client middleware only receives id, not name or filename:

+
+ Client Captured ID:{' '} + + {loaderData.clientCapturedMeta?.id} + +
+
+ Client Captured Name:{' '} + + {/* Cast to any to test that name is not present at runtime */} + {(loaderData.clientCapturedMeta as any)?.name ?? 'undefined'} + +
+
+ Client Captured Filename:{' '} + + {/* Cast to any to test that filename is not present at runtime */} + {(loaderData.clientCapturedMeta as any)?.filename ?? 'undefined'} + +
+
+
+
+ +
+
+ {clientData && ( +
+

Client Data

+

Server Captured Metadata:

+
+ Function ID:{' '} + + {clientData.serverMeta?.id} + +
+
+ Function Name:{' '} + + {clientData.serverMeta?.name} + +
+
+ Filename:{' '} + + {clientData.serverMeta?.filename} + +
+

Client Captured Metadata (via sendContext):

+

Client middleware only receives id, not name or filename:

+
+ Client Captured ID:{' '} + + {clientData.clientCapturedMeta?.id} + +
+
+ Client Captured Name:{' '} + + {/* Cast to any to test that name is not present at runtime */} + {(clientData.clientCapturedMeta as any)?.name ?? 'undefined'} + +
+
+ Client Captured Filename:{' '} + + {/* Cast to any to test that filename is not present at runtime */} + {(clientData.clientCapturedMeta as any)?.filename ?? + 'undefined'} + +
+
+ )} +
+
+ ) +} diff --git a/e2e/react-start/server-functions/src/routes/middleware/index.tsx b/e2e/react-start/server-functions/src/routes/middleware/index.tsx index 8a12ac30537..5257eeab239 100644 --- a/e2e/react-start/server-functions/src/routes/middleware/index.tsx +++ b/e2e/react-start/server-functions/src/routes/middleware/index.tsx @@ -50,6 +50,14 @@ function RouteComponent() { build +
  • + + Function middleware receives functionId and filename + +
  • ) diff --git a/e2e/react-start/server-functions/tests/server-functions.spec.ts b/e2e/react-start/server-functions/tests/server-functions.spec.ts index a428f5640ea..7bae089d125 100644 --- a/e2e/react-start/server-functions/tests/server-functions.spec.ts +++ b/e2e/react-start/server-functions/tests/server-functions.spec.ts @@ -664,3 +664,86 @@ test('middleware factories with server-only imports are stripped from client bui 'x-factory-two', ) }) + +test('function middleware receives serverFnMeta in options', async ({ + page, +}) => { + // This test verifies that: + // 1. Client middleware receives serverFnMeta with just { id } - NOT name or filename + // 2. Server middleware receives serverFnMeta with full { id, name, filename } + // 3. Client middleware can send the function metadata to the server via sendContext + await page.goto('/middleware/function-metadata') + + await page.waitForLoadState('networkidle') + + // Verify SSR data - server captured metadata should have full properties + const loaderFunctionId = await page + .getByTestId('loader-function-id') + .textContent() + const loaderFunctionName = await page + .getByTestId('loader-function-name') + .textContent() + const loaderFilename = await page.getByTestId('loader-filename').textContent() + const loaderClientCapturedId = await page + .getByTestId('loader-client-captured-id') + .textContent() + const loaderClientCapturedName = await page + .getByTestId('loader-client-captured-name') + .textContent() + const loaderClientCapturedFilename = await page + .getByTestId('loader-client-captured-filename') + .textContent() + + // id should be a non-empty string + expect(loaderFunctionId).toBeTruthy() + expect(loaderFunctionId!.length).toBeGreaterThan(0) + + // name should be the variable name of the server function + expect(loaderFunctionName).toBeTruthy() + expect(loaderFunctionName).toBe('getMetadataFn') + + // filename should be the exact route file path + expect(loaderFilename).toBe('src/routes/middleware/function-metadata.tsx') + + // Client captured ID should match the server function id + // (sent via client middleware's sendContext) + expect(loaderClientCapturedId).toBe(loaderFunctionId) + + // Client middleware should NOT have access to name or filename + // These should be "undefined" (the fallback value we display in the UI) + expect(loaderClientCapturedName).toBe('undefined') + expect(loaderClientCapturedFilename).toBe('undefined') + + // Now test client-side call + await page.getByTestId('call-server-fn-btn').click() + await page.waitForSelector('[data-testid="client-data"]') + + const clientFunctionId = await page + .getByTestId('client-function-id') + .textContent() + const clientFunctionName = await page + .getByTestId('client-function-name') + .textContent() + const clientFilename = await page.getByTestId('client-filename').textContent() + const clientClientCapturedId = await page + .getByTestId('client-client-captured-id') + .textContent() + const clientClientCapturedName = await page + .getByTestId('client-client-captured-name') + .textContent() + const clientClientCapturedFilename = await page + .getByTestId('client-client-captured-filename') + .textContent() + + // Client call should get the same server metadata + expect(clientFunctionId).toBe(loaderFunctionId) + expect(clientFunctionName).toBe(loaderFunctionName) + expect(clientFilename).toBe(loaderFilename) + + // Client captured ID from client middleware should also match + expect(clientClientCapturedId).toBe(loaderFunctionId) + + // Client middleware should NOT have access to name or filename + expect(clientClientCapturedName).toBe('undefined') + expect(clientClientCapturedFilename).toBe('undefined') +}) diff --git a/packages/start-client-core/src/client-rpc/createClientRpc.ts b/packages/start-client-core/src/client-rpc/createClientRpc.ts index aed2cf62e9f..467e9b6c29c 100644 --- a/packages/start-client-core/src/client-rpc/createClientRpc.ts +++ b/packages/start-client-core/src/client-rpc/createClientRpc.ts @@ -1,8 +1,10 @@ import { TSS_SERVER_FUNCTION } from '../constants' +import type { ClientFnMeta } from '../constants' import { serverFnFetcher } from './serverFnFetcher' export function createClientRpc(functionId: string) { const url = process.env.TSS_SERVER_FN_BASE + functionId + const serverFnMeta: ClientFnMeta = { id: functionId } const clientFn = (...args: Array) => { return serverFnFetcher(url, args, fetch) @@ -10,7 +12,7 @@ export function createClientRpc(functionId: string) { return Object.assign(clientFn, { url, - functionId, + serverFnMeta, [TSS_SERVER_FUNCTION]: true, }) } diff --git a/packages/start-client-core/src/client/ServerFunctionSerializationAdapter.ts b/packages/start-client-core/src/client/ServerFunctionSerializationAdapter.ts index 6df1f4fa6d3..743673a8c23 100644 --- a/packages/start-client-core/src/client/ServerFunctionSerializationAdapter.ts +++ b/packages/start-client-core/src/client/ServerFunctionSerializationAdapter.ts @@ -4,13 +4,13 @@ import { createClientRpc } from '../client-rpc/createClientRpc' export const ServerFunctionSerializationAdapter = createSerializationAdapter({ key: '$TSS/serverfn', - test: (v): v is { functionId: string } => { + test: (v): v is { serverFnMeta: { id: string } } => { if (typeof v !== 'function') return false if (!(TSS_SERVER_FUNCTION in v)) return false return !!v[TSS_SERVER_FUNCTION] }, - toSerializable: ({ functionId }) => ({ functionId }), + toSerializable: ({ serverFnMeta }) => ({ functionId: serverFnMeta.id }), fromSerializable: ({ functionId }) => createClientRpc(functionId), }) diff --git a/packages/start-client-core/src/constants.ts b/packages/start-client-core/src/constants.ts index 1e541af3231..37171fdbfb0 100644 --- a/packages/start-client-core/src/constants.ts +++ b/packages/start-client-core/src/constants.ts @@ -6,4 +6,25 @@ export const TSS_SERVER_FUNCTION_FACTORY = Symbol.for( export const X_TSS_SERIALIZED = 'x-tss-serialized' export const X_TSS_RAW_RESPONSE = 'x-tss-raw' + +/** + * Minimal metadata about a server function, available to client middleware. + * Only contains the function ID since name/filename may expose server internals. + */ +export interface ClientFnMeta { + /** The unique identifier for this server function */ + id: string +} + +/** + * Full metadata about a server function, available to server middleware. + * This information is embedded at compile time by the TanStack Start compiler. + */ +export interface ServerFnMeta extends ClientFnMeta { + /** The original variable name of the server function (e.g., "myServerFn") */ + name: string + /** The source file path relative to the project root (e.g., "src/routes/api.ts") */ + filename: string +} + export {} diff --git a/packages/start-client-core/src/createMiddleware.ts b/packages/start-client-core/src/createMiddleware.ts index c47c3aa1b42..519906d68fa 100644 --- a/packages/start-client-core/src/createMiddleware.ts +++ b/packages/start-client-core/src/createMiddleware.ts @@ -1,5 +1,6 @@ import type { StartInstanceOptions } from './createStart' import type { AnyServerFn, ConstrainValidator, Method } from './createServerFn' +import type { ClientFnMeta, ServerFnMeta } from './constants' import type { AnyContext, Assign, @@ -511,8 +512,7 @@ export interface FunctionMiddlewareServerFnOptions< TServerSendContext > method: Method - filename: string - functionId: string + serverFnMeta: ServerFnMeta signal: AbortSignal } @@ -608,9 +608,8 @@ export interface FunctionMiddlewareClientFnOptions< sendContext: Expand> method: Method signal: AbortSignal + serverFnMeta: ClientFnMeta next: FunctionMiddlewareClientNextFn - filename: string - functionId: string } export type FunctionMiddlewareClientFnResult< diff --git a/packages/start-client-core/src/createServerFn.ts b/packages/start-client-core/src/createServerFn.ts index 3307d4b7cee..74a57cc66bf 100644 --- a/packages/start-client-core/src/createServerFn.ts +++ b/packages/start-client-core/src/createServerFn.ts @@ -4,7 +4,11 @@ import { mergeHeaders } from '@tanstack/router-core/ssr/client' import { TSS_SERVER_FUNCTION_FACTORY } from './constants' import { getStartOptions } from './getStartOptions' import { getStartContextServerOnly } from './getStartContextServerOnly' -import type { TSS_SERVER_FUNCTION } from './constants' +import type { + ClientFnMeta, + ServerFnMeta, + TSS_SERVER_FUNCTION, +} from './constants' import type { AnyValidator, Constrain, @@ -136,6 +140,10 @@ export const createServerFn: CreateServerFn = (options, __opts) => { const ctx = { ...extractedFn, ...opts, + // Ensure we use the full serverFnMeta from the provider file's extractedFn + // (which has id, name, filename) rather than the partial one from SSR/client + // callers (which only has id) + serverFnMeta: extractedFn.serverFnMeta, context: { ...serverContextAfterGlobalMiddlewares, ...opts.context, @@ -326,6 +334,7 @@ export type CompiledFetcherFn = { opts: CompiledFetcherFnOptions & ServerFnBaseOptions, ): Promise url: string + serverFnMeta: ServerFnMeta } export type ServerFnBaseOptions< @@ -349,7 +358,6 @@ export type ServerFnBaseOptions< TInputValidator, TResponse > - functionId: string } export type ValidateValidatorInput< @@ -604,7 +612,7 @@ export type ServerFnMiddlewareOptions = { signal?: AbortSignal sendContext?: any context?: any - functionId: string + serverFnMeta: ClientFnMeta } export type ServerFnMiddlewareResult = ServerFnMiddlewareOptions & { diff --git a/packages/start-client-core/src/index.tsx b/packages/start-client-core/src/index.tsx index eb5f7eb8f0e..71522274a22 100644 --- a/packages/start-client-core/src/index.tsx +++ b/packages/start-client-core/src/index.tsx @@ -84,6 +84,7 @@ export { X_TSS_SERIALIZED, X_TSS_RAW_RESPONSE, } from './constants' +export type { ClientFnMeta, ServerFnMeta } from './constants' export type * from './serverRoute' diff --git a/packages/start-plugin-core/src/start-compiler-plugin/handleCreateServerFn.ts b/packages/start-plugin-core/src/start-compiler-plugin/handleCreateServerFn.ts index b83c922b5bf..a34ff28f21f 100644 --- a/packages/start-plugin-core/src/start-compiler-plugin/handleCreateServerFn.ts +++ b/packages/start-plugin-core/src/start-compiler-plugin/handleCreateServerFn.ts @@ -12,22 +12,22 @@ const TSS_SERVERFN_SPLIT_PARAM = 'tss-serverfn-split' // Pre-compiled babel templates (compiled once at module load time) // ============================================================================ -// Template for provider files: createServerRpc('id', fn) +// Template for provider files: createServerRpc(serverFnMeta, fn) const serverRpcTemplate = babel.template.expression( - `createServerRpc(%%functionId%%, %%fn%%)`, + `createServerRpc(%%serverFnMeta%%, %%fn%%)`, ) -// Template for client caller files: createClientRpc('id') +// Template for client caller files: createClientRpc(functionId) const clientRpcTemplate = babel.template.expression( `createClientRpc(%%functionId%%)`, ) -// Template for SSR caller files (manifest lookup): createSsrRpc('id') +// Template for SSR caller files (manifest lookup): createSsrRpc(functionId) const ssrRpcManifestTemplate = babel.template.expression( `createSsrRpc(%%functionId%%)`, ) -// Template for SSR caller files (with importer): createSsrRpc('id', () => import(...).then(m => m['name'])) +// Template for SSR caller files (with importer): createSsrRpc(functionId, () => import(...).then(m => m['name'])) const ssrRpcImporterTemplate = babel.template.expression( `createSsrRpc(%%functionId%%, () => import(%%extractedFilename%%).then(m => m[%%functionName%%]))`, ) @@ -117,16 +117,32 @@ function getEnvConfig( } } +/** + * Builds the serverFnMeta object literal AST node. + * The object contains: { id, name, filename } + */ +function buildServerFnMetaObject( + functionId: string, + variableName: string, + filename: string, +): t.ObjectExpression { + return t.objectExpression([ + t.objectProperty(t.identifier('id'), t.stringLiteral(functionId)), + t.objectProperty(t.identifier('name'), t.stringLiteral(variableName)), + t.objectProperty(t.identifier('filename'), t.stringLiteral(filename)), + ]) +} + /** * Generates the RPC stub expression for provider files. * Uses pre-compiled template for performance. */ function generateProviderRpcStub( - functionId: string, + serverFnMeta: t.ObjectExpression, fn: t.Expression, ): t.Expression { return serverRpcTemplate({ - functionId: t.stringLiteral(functionId), + serverFnMeta, fn, }) } @@ -134,6 +150,7 @@ function generateProviderRpcStub( /** * Generates the RPC stub expression for caller files. * Uses pre-compiled templates for performance. + * Note: Client and SSR callers only receive the functionId string, not the full metadata. */ function generateCallerRpcStub( functionId: string, @@ -142,9 +159,11 @@ function generateCallerRpcStub( isClientReferenced: boolean, envConfig: EnvConfig, ): t.Expression { + const functionIdLiteral = t.stringLiteral(functionId) + if (envConfig.runtimeCodeType === 'client') { return clientRpcTemplate({ - functionId: t.stringLiteral(functionId), + functionId: functionIdLiteral, }) } @@ -154,12 +173,12 @@ function generateCallerRpcStub( // Otherwise, use the importer for functions only referenced on the server when SSR is the provider if (isClientReferenced || !envConfig.ssrIsProvider) { return ssrRpcManifestTemplate({ - functionId: t.stringLiteral(functionId), + functionId: functionIdLiteral, }) } return ssrRpcImporterTemplate({ - functionId: t.stringLiteral(functionId), + functionId: functionIdLiteral, extractedFilename: t.stringLiteral(extractedFilename), functionName: t.stringLiteral(functionName), }) @@ -306,7 +325,7 @@ export function handleCreateServerFn( // 2. Modify .handler() to pass (extractedFn, serverFn) - two arguments // // Expected output format: - // const extractedFn = createServerRpc("id", (opts) => varName.__executeServer(opts)); + // const extractedFn = createServerRpc({id, name, filename}, (opts) => varName.__executeServer(opts)); // const varName = createServerFn().handler(extractedFn, originalHandler); // Build the arrow function: (opts, signal) => varName.__executeServer(opts, signal) @@ -322,9 +341,16 @@ export function handleCreateServerFn( ), ) + // Build the serverFnMeta object + const serverFnMeta = buildServerFnMetaObject( + functionId, + existingVariableName, + relativeFilename, + ) + // Generate the replacement using pre-compiled template const extractedFnInit = generateProviderRpcStub( - functionId, + serverFnMeta, executeServerArrowFn, ) @@ -381,6 +407,7 @@ export function handleCreateServerFn( } // Generate the RPC stub using pre-compiled templates + // Note: Caller files only pass functionId, not the full serverFnMeta const rpcStub = generateCallerRpcStub( functionId, functionName, diff --git a/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts b/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts index a039321781f..a861c51a82e 100644 --- a/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts +++ b/packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts @@ -25,7 +25,8 @@ async function compile(opts: { code: string isProviderFile: boolean }) { - let id = 'test.ts' + // Use an absolute path inside the test root to ensure consistent filename output + let id = '/test/src/test.ts' if (opts.isProviderFile) { id += `?${TSS_SERVERFN_SPLIT_PARAM}` @@ -121,14 +122,14 @@ describe('createServerFn compiles correctly', async () => { expect(compiledResultClient!.code).toMatchInlineSnapshot(` "import { createClientRpc } from '@tanstack/react-start/client-rpc'; import { createServerFn } from '@tanstack/react-start'; - const myServerFn = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im15U2VydmVyRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9"));" + const myServerFn = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJteVNlcnZlckZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ"));" `) // Server caller: no second argument (implementation from extracted chunk) expect(compiledResultServerCaller!.code).toMatchInlineSnapshot(` "import { createSsrRpc } from '@tanstack/react-start/ssr-rpc'; import { createServerFn } from '@tanstack/react-start'; - const myServerFn = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im15U2VydmVyRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["myServerFn_createServerFn_handler"])));" + const myServerFn = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJteVNlcnZlckZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["myServerFn_createServerFn_handler"])));" `) // Server provider: has second argument (this is the implementation file) @@ -138,7 +139,11 @@ describe('createServerFn compiles correctly', async () => { const myFunc = () => { return 'hello from the server'; }; - const myServerFn_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im15U2VydmVyRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => myServerFn.__executeServer(opts, signal)); + const myServerFn_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJteVNlcnZlckZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "myServerFn", + filename: "src/test.ts" + }, (opts, signal) => myServerFn.__executeServer(opts, signal)); const myServerFn = createServerFn().handler(myServerFn_createServerFn_handler, myFunc); export { myServerFn_createServerFn_handler };" `) @@ -166,8 +171,8 @@ describe('createServerFn compiles correctly', async () => { expect(compiledResult!.code).toMatchInlineSnapshot(` "import { createClientRpc } from '@tanstack/react-start/client-rpc'; import { createServerFn } from '@tanstack/react-start'; - export const exportedFn = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImV4cG9ydGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); - const nonExportedFn = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im5vbkV4cG9ydGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9"));" + export const exportedFn = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJleHBvcnRlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); + const nonExportedFn = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJub25FeHBvcnRlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ"));" `) // Server caller (route file) - no second argument @@ -180,8 +185,8 @@ describe('createServerFn compiles correctly', async () => { expect(compiledResultServerCaller!.code).toMatchInlineSnapshot(` "import { createSsrRpc } from '@tanstack/react-start/ssr-rpc'; import { createServerFn } from '@tanstack/react-start'; - export const exportedFn = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImV4cG9ydGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["exportedFn_createServerFn_handler"]))); - const nonExportedFn = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im5vbkV4cG9ydGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["nonExportedFn_createServerFn_handler"])));" + export const exportedFn = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJleHBvcnRlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["exportedFn_createServerFn_handler"]))); + const nonExportedFn = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJub25FeHBvcnRlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["nonExportedFn_createServerFn_handler"])));" `) // Server provider (extracted file) - has second argument @@ -195,12 +200,20 @@ describe('createServerFn compiles correctly', async () => { "import { createServerRpc } from '@tanstack/react-start/server-rpc'; import { createServerFn } from '@tanstack/react-start'; const exportedVar = 'exported'; - const exportedFn_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImV4cG9ydGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => exportedFn.__executeServer(opts, signal)); + const exportedFn_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJleHBvcnRlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "exportedFn", + filename: "src/test.ts" + }, (opts, signal) => exportedFn.__executeServer(opts, signal)); const exportedFn = createServerFn().handler(exportedFn_createServerFn_handler, async () => { return exportedVar; }); const nonExportedVar = 'non-exported'; - const nonExportedFn_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im5vbkV4cG9ydGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => nonExportedFn.__executeServer(opts, signal)); + const nonExportedFn_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJub25FeHBvcnRlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "nonExportedFn", + filename: "src/test.ts" + }, (opts, signal) => nonExportedFn.__executeServer(opts, signal)); const nonExportedFn = createServerFn().handler(nonExportedFn_createServerFn_handler, async () => { return nonExportedVar; }); @@ -234,7 +247,7 @@ describe('createServerFn compiles correctly', async () => { await compiler.compile({ code, - id: 'test.ts', + id: '/test/src/test.ts', }) // resolveId should only be called once during init() for the library itself @@ -285,7 +298,7 @@ describe('createServerFn compiles correctly', async () => { await compiler.compile({ code: factoryCode, - id: 'test.ts', + id: '/test/src/test.ts', }) // resolveId should be called exactly twice: @@ -300,6 +313,10 @@ describe('createServerFn compiles correctly', async () => { '@tanstack/react-start', undefined, ) - expect(resolveIdMock).toHaveBeenNthCalledWith(2, './factory', 'test.ts') + expect(resolveIdMock).toHaveBeenNthCalledWith( + 2, + './factory', + '/test/src/test.ts', + ) }) }) diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructured.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructured.tsx index a26d8b38517..51f40ea4f77 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructured.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructured.tsx @@ -2,22 +2,22 @@ import { createClientRpc } from '@tanstack/react-start/client-rpc'; import { createServerFn } from '@tanstack/react-start'; export const withUseServer = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withArrowFunction = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhBcnJvd0Z1bmN0aW9uX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoQXJyb3dGdW5jdGlvbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); export const withArrowFunctionAndFunction = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhBcnJvd0Z1bmN0aW9uQW5kRnVuY3Rpb25fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoQXJyb3dGdW5jdGlvbkFuZEZ1bmN0aW9uX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withoutUseServer = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withVariable = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); export const withZodValidator = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withValidatorFn = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYWxpZGF0b3JGbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); \ No newline at end of file +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFsaWRhdG9yRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructuredRename.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructuredRename.tsx index 4faeee53249..2d2dfaf15ac 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructuredRename.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnDestructuredRename.tsx @@ -2,13 +2,13 @@ import { createClientRpc } from '@tanstack/react-start/client-rpc'; import { createServerFn as serverFn } from '@tanstack/react-start'; export const withUseServer = serverFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withoutUseServer = serverFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withVariable = serverFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); export const withZodValidator = serverFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); \ No newline at end of file +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnStarImport.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnStarImport.tsx index a6bb257000a..16a447fa01f 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnStarImport.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnStarImport.tsx @@ -2,13 +2,13 @@ import { createClientRpc } from '@tanstack/react-start/client-rpc'; import * as TanStackStart from '@tanstack/react-start'; export const withUseServer = TanStackStart.createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withoutUseServer = TanStackStart.createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const withVariable = TanStackStart.createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); export const withZodValidator = TanStackStart.createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); \ No newline at end of file +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnValidator.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnValidator.tsx index a62a7b6e60b..5e1b05659ef 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnValidator.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/client/createServerFnValidator.tsx @@ -2,4 +2,4 @@ import { createClientRpc } from '@tanstack/react-start/client-rpc'; import { createServerFn } from '@tanstack/react-start'; export const withUseServer = createServerFn({ method: 'GET' -}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); \ No newline at end of file +}).handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/client/factory.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/client/factory.tsx index d9b5f242e34..ded08d457cc 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/client/factory.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/client/factory.tsx @@ -24,8 +24,8 @@ const adminMiddleware = createMiddleware({ }); export const createAuthServerFn = createServerFn().middleware([authMiddleware]); const createAdminServerFn = createAuthServerFn().middleware([adminMiddleware]); -export const myAuthedFn = createAuthServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im15QXV0aGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); -export const deleteUserFn = createAdminServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImRlbGV0ZVVzZXJGbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); +export const myAuthedFn = createAuthServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJteUF1dGhlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); +export const deleteUserFn = createAdminServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJkZWxldGVVc2VyRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); function createFakeFn() { return { handler: cb => { diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/client/isomorphic-fns.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/client/isomorphic-fns.tsx index b1cd8f3f2ed..0a013b8db1a 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/client/isomorphic-fns.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/client/isomorphic-fns.tsx @@ -3,9 +3,9 @@ import { createFileRoute } from '@tanstack/react-router'; import { createIsomorphicFn, createServerFn } from '@tanstack/react-start'; import { useState } from 'react'; const getEnv = createIsomorphicFn().server(() => 'server').client(() => 'client'); -const getServerEnv = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImdldFNlcnZlckVudl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0")); +const getServerEnv = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJnZXRTZXJ2ZXJFbnZfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); const getEcho = createIsomorphicFn().server((input: string) => 'server received ' + input).client(input => 'client received ' + input); -const getServerEcho = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImdldFNlcnZlckVjaG9fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9")); +const getServerEcho = createServerFn().handler(createClientRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJnZXRTZXJ2ZXJFY2hvX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ")); export const Route = createFileRoute('/isomorphic-fns')({ component: RouteComponent, loader() { diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructured.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructured.tsx index 83f912ad8a0..b8dbdcaae58 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructured.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructured.tsx @@ -3,22 +3,22 @@ import { createServerFn } from '@tanstack/react-start'; import { z } from 'zod'; export const withUseServer = createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); export const withArrowFunction = createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhBcnJvd0Z1bmN0aW9uX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("test.ts?tss-serverfn-split").then(m => m["withArrowFunction_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoQXJyb3dGdW5jdGlvbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withArrowFunction_createServerFn_handler"]))); export const withArrowFunctionAndFunction = createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhBcnJvd0Z1bmN0aW9uQW5kRnVuY3Rpb25fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withArrowFunctionAndFunction_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoQXJyb3dGdW5jdGlvbkFuZEZ1bmN0aW9uX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withArrowFunctionAndFunction_createServerFn_handler"]))); export const withoutUseServer = createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withoutUseServer_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withoutUseServer_createServerFn_handler"]))); export const withVariable = createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("test.ts?tss-serverfn-split").then(m => m["withVariable_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withVariable_createServerFn_handler"]))); export const withZodValidator = createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withZodValidator_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withZodValidator_createServerFn_handler"]))); export const withValidatorFn = createServerFn({ method: 'GET' -}).inputValidator(z.number()).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYWxpZGF0b3JGbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("test.ts?tss-serverfn-split").then(m => m["withValidatorFn_createServerFn_handler"]))); \ No newline at end of file +}).inputValidator(z.number()).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFsaWRhdG9yRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withValidatorFn_createServerFn_handler"]))); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructuredRename.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructuredRename.tsx index bfaa169987d..815702d5d8f 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructuredRename.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnDestructuredRename.tsx @@ -2,13 +2,13 @@ import { createSsrRpc } from '@tanstack/react-start/ssr-rpc'; import { createServerFn as serverFn } from '@tanstack/react-start'; export const withUseServer = serverFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); export const withoutUseServer = serverFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withoutUseServer_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withoutUseServer_createServerFn_handler"]))); export const withVariable = serverFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("test.ts?tss-serverfn-split").then(m => m["withVariable_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withVariable_createServerFn_handler"]))); export const withZodValidator = serverFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withZodValidator_createServerFn_handler"]))); \ No newline at end of file +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withZodValidator_createServerFn_handler"]))); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnStarImport.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnStarImport.tsx index ab56b02c518..2f68c8c276d 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnStarImport.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnStarImport.tsx @@ -2,13 +2,13 @@ import { createSsrRpc } from '@tanstack/react-start/ssr-rpc'; import * as TanStackStart from '@tanstack/react-start'; export const withUseServer = TanStackStart.createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); export const withoutUseServer = TanStackStart.createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withoutUseServer_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withoutUseServer_createServerFn_handler"]))); export const withVariable = TanStackStart.createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("test.ts?tss-serverfn-split").then(m => m["withVariable_createServerFn_handler"]))); +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withVariable_createServerFn_handler"]))); export const withZodValidator = TanStackStart.createServerFn({ method: 'GET' -}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withZodValidator_createServerFn_handler"]))); \ No newline at end of file +}).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withZodValidator_createServerFn_handler"]))); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnValidator.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnValidator.tsx index a614a804095..ba0b4b577e2 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnValidator.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/createServerFnValidator.tsx @@ -3,4 +3,4 @@ import { createServerFn } from '@tanstack/react-start'; import { z } from 'zod'; export const withUseServer = createServerFn({ method: 'GET' -}).inputValidator(z.number()).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); \ No newline at end of file +}).inputValidator(z.number()).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["withUseServer_createServerFn_handler"]))); \ No newline at end of file diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/factory.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/factory.tsx index 372b97d5283..dbc4e764d9a 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/factory.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/factory.tsx @@ -24,8 +24,8 @@ const adminMiddleware = createMiddleware({ }); export const createAuthServerFn = createServerFn().middleware([authMiddleware]); const createAdminServerFn = createAuthServerFn().middleware([adminMiddleware]); -export const myAuthedFn = createAuthServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im15QXV0aGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["myAuthedFn_createServerFn_handler"]))); -export const deleteUserFn = createAdminServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImRlbGV0ZVVzZXJGbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("test.ts?tss-serverfn-split").then(m => m["deleteUserFn_createServerFn_handler"]))); +export const myAuthedFn = createAuthServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJteUF1dGhlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["myAuthedFn_createServerFn_handler"]))); +export const deleteUserFn = createAdminServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJkZWxldGVVc2VyRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["deleteUserFn_createServerFn_handler"]))); function createFakeFn() { return { handler: cb => { diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/isomorphic-fns.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/isomorphic-fns.tsx index cd2823e6fe8..02675e9e956 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/isomorphic-fns.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-caller/isomorphic-fns.tsx @@ -3,9 +3,9 @@ import { createFileRoute } from '@tanstack/react-router'; import { createIsomorphicFn, createServerFn } from '@tanstack/react-start'; import { useState } from 'react'; const getEnv = createIsomorphicFn().server(() => 'server').client(() => 'client'); -const getServerEnv = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImdldFNlcnZlckVudl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", () => import("test.ts?tss-serverfn-split").then(m => m["getServerEnv_createServerFn_handler"]))); +const getServerEnv = createServerFn().handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJnZXRTZXJ2ZXJFbnZfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["getServerEnv_createServerFn_handler"]))); const getEcho = createIsomorphicFn().server((input: string) => 'server received ' + input).client(input => 'client received ' + input); -const getServerEcho = createServerFn().inputValidator((input: string) => input).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImdldFNlcnZlckVjaG9fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", () => import("test.ts?tss-serverfn-split").then(m => m["getServerEcho_createServerFn_handler"]))); +const getServerEcho = createServerFn().inputValidator((input: string) => input).handler(createSsrRpc("eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJnZXRTZXJ2ZXJFY2hvX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", () => import("/test/src/test.ts?tss-serverfn-split").then(m => m["getServerEcho_createServerFn_handler"]))); export const Route = createFileRoute('/isomorphic-fns')({ component: RouteComponent, loader() { diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructured.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructured.tsx index 69fa019eb9f..4a5f22b80a3 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructured.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructured.tsx @@ -1,7 +1,11 @@ import { createServerRpc } from '@tanstack/react-start/server-rpc'; import { createServerFn } from '@tanstack/react-start'; import { z } from 'zod'; -const withUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withUseServer.__executeServer(opts, signal)); +const withUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withUseServer", + filename: "src/test.ts" +}, (opts, signal) => withUseServer.__executeServer(opts, signal)); const withUseServer = createServerFn({ method: 'GET' }).handler(withUseServer_createServerFn_handler, async function () { @@ -9,15 +13,27 @@ const withUseServer = createServerFn({ await new Promise(r => setTimeout(r, 500)); return axios.get>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); }); -const withArrowFunction_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhBcnJvd0Z1bmN0aW9uX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", (opts, signal) => withArrowFunction.__executeServer(opts, signal)); +const withArrowFunction_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoQXJyb3dGdW5jdGlvbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", + name: "withArrowFunction", + filename: "src/test.ts" +}, (opts, signal) => withArrowFunction.__executeServer(opts, signal)); const withArrowFunction = createServerFn({ method: 'GET' }).handler(withArrowFunction_createServerFn_handler, async () => null); -const withArrowFunctionAndFunction_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhBcnJvd0Z1bmN0aW9uQW5kRnVuY3Rpb25fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withArrowFunctionAndFunction.__executeServer(opts, signal)); +const withArrowFunctionAndFunction_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoQXJyb3dGdW5jdGlvbkFuZEZ1bmN0aW9uX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withArrowFunctionAndFunction", + filename: "src/test.ts" +}, (opts, signal) => withArrowFunctionAndFunction.__executeServer(opts, signal)); const withArrowFunctionAndFunction = createServerFn({ method: 'GET' }).handler(withArrowFunctionAndFunction_createServerFn_handler, async () => test()); -const withoutUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withoutUseServer.__executeServer(opts, signal)); +const withoutUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withoutUseServer", + filename: "src/test.ts" +}, (opts, signal) => withoutUseServer.__executeServer(opts, signal)); const withoutUseServer = createServerFn({ method: 'GET' }).handler(withoutUseServer_createServerFn_handler, async () => { @@ -25,7 +41,11 @@ const withoutUseServer = createServerFn({ await new Promise(r => setTimeout(r, 500)); return axios.get>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); }); -const withVariable_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", (opts, signal) => withVariable.__executeServer(opts, signal)); +const withVariable_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", + name: "withVariable", + filename: "src/test.ts" +}, (opts, signal) => withVariable.__executeServer(opts, signal)); const withVariable = createServerFn({ method: 'GET' }).handler(withVariable_createServerFn_handler, abstractedFunction); @@ -39,7 +59,11 @@ function zodValidator(schema: TSchema, fn: return fn(schema.parse(input)); }; } -const withZodValidator_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withZodValidator.__executeServer(opts, signal)); +const withZodValidator_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withZodValidator", + filename: "src/test.ts" +}, (opts, signal) => withZodValidator.__executeServer(opts, signal)); const withZodValidator = createServerFn({ method: 'GET' }).handler(withZodValidator_createServerFn_handler, zodValidator(z.number(), input => { @@ -47,7 +71,11 @@ const withZodValidator = createServerFn({ 'you gave': input }; })); -const withValidatorFn_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYWxpZGF0b3JGbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", (opts, signal) => withValidatorFn.__executeServer(opts, signal)); +const withValidatorFn_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFsaWRhdG9yRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", + name: "withValidatorFn", + filename: "src/test.ts" +}, (opts, signal) => withValidatorFn.__executeServer(opts, signal)); const withValidatorFn = createServerFn({ method: 'GET' }).inputValidator(z.number()).handler(withValidatorFn_createServerFn_handler, async ({ diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructuredRename.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructuredRename.tsx index cb14a1e1cde..0a88404f7de 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructuredRename.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnDestructuredRename.tsx @@ -1,7 +1,11 @@ import { createServerRpc } from '@tanstack/react-start/server-rpc'; import { createServerFn as serverFn } from '@tanstack/react-start'; import { z } from 'zod'; -const withUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withUseServer.__executeServer(opts, signal)); +const withUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withUseServer", + filename: "src/test.ts" +}, (opts, signal) => withUseServer.__executeServer(opts, signal)); const withUseServer = serverFn({ method: 'GET' }).handler(withUseServer_createServerFn_handler, async function () { @@ -9,7 +13,11 @@ const withUseServer = serverFn({ await new Promise(r => setTimeout(r, 500)); return axios.get>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); }); -const withoutUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withoutUseServer.__executeServer(opts, signal)); +const withoutUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withoutUseServer", + filename: "src/test.ts" +}, (opts, signal) => withoutUseServer.__executeServer(opts, signal)); const withoutUseServer = serverFn({ method: 'GET' }).handler(withoutUseServer_createServerFn_handler, async () => { @@ -17,7 +25,11 @@ const withoutUseServer = serverFn({ await new Promise(r => setTimeout(r, 500)); return axios.get>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); }); -const withVariable_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", (opts, signal) => withVariable.__executeServer(opts, signal)); +const withVariable_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", + name: "withVariable", + filename: "src/test.ts" +}, (opts, signal) => withVariable.__executeServer(opts, signal)); const withVariable = serverFn({ method: 'GET' }).handler(withVariable_createServerFn_handler, abstractedFunction); @@ -31,7 +43,11 @@ function zodValidator(schema: TSchema, fn: return fn(schema.parse(input)); }; } -const withZodValidator_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withZodValidator.__executeServer(opts, signal)); +const withZodValidator_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withZodValidator", + filename: "src/test.ts" +}, (opts, signal) => withZodValidator.__executeServer(opts, signal)); const withZodValidator = serverFn({ method: 'GET' }).handler(withZodValidator_createServerFn_handler, zodValidator(z.number(), input => { diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnStarImport.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnStarImport.tsx index ce3152eb083..92e17b934e8 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnStarImport.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnStarImport.tsx @@ -1,7 +1,11 @@ import { createServerRpc } from '@tanstack/react-start/server-rpc'; import * as TanStackStart from '@tanstack/react-start'; import { z } from 'zod'; -const withUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withUseServer.__executeServer(opts, signal)); +const withUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withUseServer", + filename: "src/test.ts" +}, (opts, signal) => withUseServer.__executeServer(opts, signal)); const withUseServer = TanStackStart.createServerFn({ method: 'GET' }).handler(withUseServer_createServerFn_handler, async function () { @@ -11,7 +15,11 @@ const withUseServer = TanStackStart.createServerFn({ await new Promise(r => setTimeout(r, 500)); return axios.get>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); }); -const withoutUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhvdXRVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withoutUseServer.__executeServer(opts, signal)); +const withoutUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRob3V0VXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withoutUseServer", + filename: "src/test.ts" +}, (opts, signal) => withoutUseServer.__executeServer(opts, signal)); const withoutUseServer = TanStackStart.createServerFn({ method: 'GET' }).handler(withoutUseServer_createServerFn_handler, async () => { @@ -19,7 +27,11 @@ const withoutUseServer = TanStackStart.createServerFn({ await new Promise(r => setTimeout(r, 500)); return axios.get>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); }); -const withVariable_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhWYXJpYWJsZV9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", (opts, signal) => withVariable.__executeServer(opts, signal)); +const withVariable_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVmFyaWFibGVfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", + name: "withVariable", + filename: "src/test.ts" +}, (opts, signal) => withVariable.__executeServer(opts, signal)); const withVariable = TanStackStart.createServerFn({ method: 'GET' }).handler(withVariable_createServerFn_handler, abstractedFunction); @@ -33,7 +45,11 @@ function zodValidator(schema: TSchema, fn: return fn(schema.parse(input)); }; } -const withZodValidator_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhab2RWYWxpZGF0b3JfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withZodValidator.__executeServer(opts, signal)); +const withZodValidator_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoWm9kVmFsaWRhdG9yX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withZodValidator", + filename: "src/test.ts" +}, (opts, signal) => withZodValidator.__executeServer(opts, signal)); const withZodValidator = TanStackStart.createServerFn({ method: 'GET' }).handler(withZodValidator_createServerFn_handler, zodValidator(z.number(), input => { diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnValidator.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnValidator.tsx index 8b353869ac3..ae6c2eade66 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnValidator.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/createServerFnValidator.tsx @@ -1,7 +1,11 @@ import { createServerRpc } from '@tanstack/react-start/server-rpc'; import { createServerFn } from '@tanstack/react-start'; import { z } from 'zod'; -const withUseServer_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6IndpdGhVc2VTZXJ2ZXJfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => withUseServer.__executeServer(opts, signal)); +const withUseServer_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJ3aXRoVXNlU2VydmVyX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "withUseServer", + filename: "src/test.ts" +}, (opts, signal) => withUseServer.__executeServer(opts, signal)); const withUseServer = createServerFn({ method: 'GET' }).inputValidator(z.number()).handler(withUseServer_createServerFn_handler, ({ diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/factory.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/factory.tsx index 9443f0b1f49..d906532e048 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/factory.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/factory.tsx @@ -24,11 +24,19 @@ const adminMiddleware = createMiddleware({ }); const createAuthServerFn = createServerFn().middleware([authMiddleware]); const createAdminServerFn = createAuthServerFn().middleware([adminMiddleware]); -const myAuthedFn_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6Im15QXV0aGVkRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => myAuthedFn.__executeServer(opts, signal)); +const myAuthedFn_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJteUF1dGhlZEZuX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "myAuthedFn", + filename: "src/test.ts" +}, (opts, signal) => myAuthedFn.__executeServer(opts, signal)); const myAuthedFn = createAuthServerFn().handler(myAuthedFn_createServerFn_handler, () => { return 'myAuthedFn'; }); -const deleteUserFn_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImRlbGV0ZVVzZXJGbl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", (opts, signal) => deleteUserFn.__executeServer(opts, signal)); +const deleteUserFn_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJkZWxldGVVc2VyRm5fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", + name: "deleteUserFn", + filename: "src/test.ts" +}, (opts, signal) => deleteUserFn.__executeServer(opts, signal)); const deleteUserFn = createAdminServerFn().handler(deleteUserFn_createServerFn_handler, () => { return 'deleteUserFn'; }); diff --git a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/isomorphic-fns.tsx b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/isomorphic-fns.tsx index 5dc29d66b5e..253448da6f6 100644 --- a/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/isomorphic-fns.tsx +++ b/packages/start-plugin-core/tests/createServerFn/snapshots/server-provider/isomorphic-fns.tsx @@ -3,10 +3,18 @@ import { createFileRoute } from '@tanstack/react-router'; import { createIsomorphicFn, createServerFn } from '@tanstack/react-start'; import { useState } from 'react'; const getEnv = createIsomorphicFn().server(() => 'server').client(() => 'client'); -const getServerEnv_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImdldFNlcnZlckVudl9jcmVhdGVTZXJ2ZXJGbl9oYW5kbGVyIn0", (opts, signal) => getServerEnv.__executeServer(opts, signal)); +const getServerEnv_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJnZXRTZXJ2ZXJFbnZfY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", + name: "getServerEnv", + filename: "src/test.ts" +}, (opts, signal) => getServerEnv.__executeServer(opts, signal)); const getServerEnv = createServerFn().handler(getServerEnv_createServerFn_handler, () => getEnv()); const getEcho = createIsomorphicFn().server((input: string) => 'server received ' + input).client(input => 'client received ' + input); -const getServerEcho_createServerFn_handler = createServerRpc("eyJmaWxlIjoiL0BpZC90ZXN0LnRzP3Rzcy1zZXJ2ZXJmbi1zcGxpdCIsImV4cG9ydCI6ImdldFNlcnZlckVjaG9fY3JlYXRlU2VydmVyRm5faGFuZGxlciJ9", (opts, signal) => getServerEcho.__executeServer(opts, signal)); +const getServerEcho_createServerFn_handler = createServerRpc({ + id: "eyJmaWxlIjoiL0BpZC9zcmMvdGVzdC50cz90c3Mtc2VydmVyZm4tc3BsaXQiLCJleHBvcnQiOiJnZXRTZXJ2ZXJFY2hvX2NyZWF0ZVNlcnZlckZuX2hhbmRsZXIifQ", + name: "getServerEcho", + filename: "src/test.ts" +}, (opts, signal) => getServerEcho.__executeServer(opts, signal)); const getServerEcho = createServerFn().inputValidator((input: string) => input).handler(getServerEcho_createServerFn_handler, ({ data }) => getEcho(data)); diff --git a/packages/start-server-core/src/createServerRpc.ts b/packages/start-server-core/src/createServerRpc.ts index 02fe8d42f45..eff3044e8da 100644 --- a/packages/start-server-core/src/createServerRpc.ts +++ b/packages/start-server-core/src/createServerRpc.ts @@ -1,11 +1,17 @@ -import { TSS_SERVER_FUNCTION } from '@tanstack/start-client-core' +import { + TSS_SERVER_FUNCTION, + type ServerFnMeta, +} from '@tanstack/start-client-core' export const createServerRpc = ( - functionId: string, + serverFnMeta: ServerFnMeta, splitImportFn: (...args: any) => any, ) => { + const url = process.env.TSS_SERVER_FN_BASE + serverFnMeta.id + return Object.assign(splitImportFn, { - functionId, + url, + serverFnMeta, [TSS_SERVER_FUNCTION]: true, }) } diff --git a/packages/start-server-core/src/createSsrRpc.ts b/packages/start-server-core/src/createSsrRpc.ts index 59cf1b4bf2c..1e6ebc9b49c 100644 --- a/packages/start-server-core/src/createSsrRpc.ts +++ b/packages/start-server-core/src/createSsrRpc.ts @@ -1,4 +1,5 @@ import { TSS_SERVER_FUNCTION } from '@tanstack/start-client-core' +import type { ClientFnMeta } from '@tanstack/start-client-core' import { getServerFnById } from './getServerFnById' import type { ServerFn } from '#tanstack-start-server-fn-resolver' @@ -6,6 +7,8 @@ export type SsrRpcImporter = () => Promise export const createSsrRpc = (functionId: string, importer?: SsrRpcImporter) => { const url = process.env.TSS_SERVER_FN_BASE + functionId + const serverFnMeta: ClientFnMeta = { id: functionId } + const fn = async (...args: Array): Promise => { // If an importer is provided, use it directly (server-to-server call within the SSR environment) // Otherwise, fall back to manifest lookup (client-to-server call, server functions that are only referenced on the server or if the provider environment is not SSR) @@ -17,7 +20,7 @@ export const createSsrRpc = (functionId: string, importer?: SsrRpcImporter) => { return Object.assign(fn, { url, - functionId, + serverFnMeta, [TSS_SERVER_FUNCTION]: true, }) } diff --git a/packages/start-server-core/src/serializer/ServerFunctionSerializationAdapter.ts b/packages/start-server-core/src/serializer/ServerFunctionSerializationAdapter.ts index 6a1f701aab8..3969cd3c5d2 100644 --- a/packages/start-server-core/src/serializer/ServerFunctionSerializationAdapter.ts +++ b/packages/start-server-core/src/serializer/ServerFunctionSerializationAdapter.ts @@ -5,14 +5,14 @@ import { getServerFnById } from '../getServerFnById' export const ServerFunctionSerializationAdapter = createSerializationAdapter({ key: '$TSS/serverfn', - test: (v): v is { functionId: string } => { + test: (v): v is { serverFnMeta: { id: string } } => { if (typeof v !== 'function') return false if (!(TSS_SERVER_FUNCTION in v)) return false return !!v[TSS_SERVER_FUNCTION] }, - toSerializable: ({ functionId }) => ({ functionId }), + toSerializable: ({ serverFnMeta }) => ({ functionId: serverFnMeta.id }), fromSerializable: ({ functionId }) => { const fn = async (opts: any, signal: any): Promise => { // When a function ID is received through serialization (e.g., as a parameter @@ -22,6 +22,6 @@ export const ServerFunctionSerializationAdapter = createSerializationAdapter({ const result = await serverFn(opts ?? {}, signal) return result.result } - return createServerRpc(functionId, fn) + return fn as never }, }) diff --git a/packages/start-static-server-functions/src/staticFunctionMiddleware.ts b/packages/start-static-server-functions/src/staticFunctionMiddleware.ts index 2a077de3e80..818d2ec0d34 100644 --- a/packages/start-static-server-functions/src/staticFunctionMiddleware.ts +++ b/packages/start-static-server-functions/src/staticFunctionMiddleware.ts @@ -133,7 +133,7 @@ export const staticFunctionMiddleware = createMiddleware({ type: 'function' }) typeof document !== 'undefined' ) { const response = await fetchItem({ - functionId: ctx.functionId, + functionId: ctx.serverFnMeta.id, data: ctx.data, }) @@ -150,7 +150,7 @@ export const staticFunctionMiddleware = createMiddleware({ type: 'function' }) const response = await ctx.next() if (process.env.NODE_ENV === 'production') { await addItemToCache({ - functionId: ctx.functionId, + functionId: ctx.serverFnMeta.id, response: { result: (response as any).result, context: ctx }, data: ctx.data, })