Skip to content

feat(server-functions): add serverFunctions.serialization for custom codecs - #464

Open
lxsmnsyc wants to merge 1 commit into
nextfrom
feat/server-function-serialization
Open

lxsmnsyc wants to merge 1 commit into
nextfrom
feat/server-function-serialization

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Adds serverFunctions.serialization, a module that sets the codec for server-function payloads on both the client and the server. It is the counterpart of SolidStart's serialization.plugins option.

solid({ serverFunctions: { serialization: './src/serialization.ts' } })

// src/serialization.ts
import { createPlugin } from '@solidjs/web/serialization';
export default { plugins: [ObjectIdPlugin] };

Changes

  • The default export is the JSONCodecOptions object from @solidjs/web/serialization: plugins, disabledFeatures, depthLimit and serializeErrorStacks.
  • A bare plugin array is shorthand for { plugins }. A SolidStart serialization.plugins module works unchanged.
  • Every compiled "use server" module imports the file and passes it as codec to configureServerFunctionsClient or configureServerFunctionsServer. This uses the same appended configure call the custom endpoint already uses.
  • The generated virtual:solid-server-function-handler also imports it, so the dev middleware and the production handler have the codec before the first dispatch.
  • The path resolves against the Vite root. A missing file is a config-time error, like configure. Both options now share one resolve helper.
  • Without the option, compiled output is byte-identical to before.
  • README: a new serialization section under options.serverFunctions.

Notes

  • The runtime replaces the whole codec setting on each configure call. The docs say not to also pass codec elsewhere.
  • The SSR hydration payload is not affected. renderToStream takes its own plugins option. SolidStart behaves the same way.
  • Feature (for disabledFeatures) is imported from seroval. Re-exporting it from @solidjs/web/serialization would need a change in solidjs/solid.

Testing

  • New src/server-functions/serialization.test.ts. It creates a project with a Money class and a seroval plugin, calls the function through the generated handler on @solidjs/web rc.16, and decodes a real Money on the client side. It covers the object export, the array export, no option, and a missing path. It fails without the change.
  • vitest run: 40 of 40 pass.
  • A production client build keeps the plugin and the codec configuration in the bundle.
  • The examples/start-ssr browser e2e suite was not run.

🤖 Generated with Claude Code

…codecs

- The option points at a module whose default export is the codec for
  server-function payloads (plugins, disabledFeatures, depthLimit,
  serializeErrorStacks). A bare plugin array is shorthand for { plugins }.
- Compiled server-function modules and the generated handler pass it as
  codec to configureServerFunctions{Client,Server}, so both ends of the
  wire use the same codec.
- Output is unchanged when the option is not set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 20d26f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/vite-plugin 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

@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/vite-plugin@464

commit: 20d26f6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant