diff --git a/docs/start/framework/react/guide/server-functions.md b/docs/start/framework/react/guide/server-functions.md index 2cbbdf0dde..b2eb913ab0 100644 --- a/docs/start/framework/react/guide/server-functions.md +++ b/docs/start/framework/react/guide/server-functions.md @@ -270,6 +270,31 @@ export default defineConfig({ }) ``` +### Custom serialization adapters + +You can create custom serialization adapters to handle complex types that can't be serialized by default. + +Example: + +```ts +// src/start.ts +import { createStart } from "@tanstack/react-start"; +import { createSerializationAdapter } from "@tanstack/react-router"; + +const bigIntAdapter = createSerializationAdapter({ + key: "bigint", + test: (value: unknown): value is bigint => typeof value === "bigint", + toSerializable: (bigInt) => bigInt.toString(), + fromSerializable: (value) => BigInt(value), +}); + +export const startInstance = createStart(() => { + return { + serializationAdapters: [bigIntAdapter], + }; +}); +``` + --- > **Note**: Server functions use a compilation process that extracts server code from client bundles while maintaining seamless calling patterns. On the client, calls become `fetch` requests to the server. diff --git a/docs/start/framework/solid/guide/server-functions.md b/docs/start/framework/solid/guide/server-functions.md index 35d8fb58a9..a654b904c0 100644 --- a/docs/start/framework/solid/guide/server-functions.md +++ b/docs/start/framework/solid/guide/server-functions.md @@ -7,3 +7,28 @@ replace: '@tanstack/react-router': '@tanstack/solid-router', } --- + +### Custom serialization adapters + +You can create custom serialization adapters to handle complex types that can't be serialized by default. + +Example: + +```ts +// src/start.ts +import { createStart } from '@tanstack/solid-start' +import { createSerializationAdapter } from '@tanstack/solid-router' + +const bigIntAdapter = createSerializationAdapter({ + key: 'bigint', + test: (value: unknown): value is bigint => typeof value === 'bigint', + toSerializable: (bigInt) => bigInt.toString(), + fromSerializable: (value) => BigInt(value), +}) + +export const startInstance = createStart(() => { + return { + serializationAdapters: [bigIntAdapter], + } +}) +```