solidjs / solidjs/solid-router

2.0: Standard Schema validation for query/action input

Open
#569 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
1.3k
Forks
180
Avg merge
1d 13h
Merged PRs (30d)
19

Description

Tracking the actionable part of #507 as a 2.0 improvement.

Problem

"use server" functions type their arguments as written (e.g. email: string), but the input actually crosses a serialization boundary and is attacker-controlled. Typing it honestly as unknown destroys caller-side DX. Users want "typed on the outside, validated on the inside."

Userland wrappers can't solve this: composing a validator around a "use server" function runs into server-function compilation constraints (Server Functions cannot be nested in other blocks or functions - see https://github.com/solidjs/solid-router/issues/507#issuecomment-2694797871), so first-class router support is the only clean path.

Proposal

Accept an optional Standard Schema validator in query and action:

const getUser = query(z.string().email(), async (email) => {
  "use server";
  // email: string, already validated at the boundary
}, "get-user");
  • Caller-side argument types derive from the schema's input type.
  • The function body receives the schema's output type, validated server-side before the body runs.
  • Standard Schema keeps the router decoupled from any particular validation library (Zod, Valibot, ArkType all implement it), same approach TanStack Router took.

Open design questions:

  • Overload shape (query(schema, fn, name) vs options object) and how it interacts with multi-argument functions.
  • Validation failure behavior (throw a typed error? 400-style response for actions?).
  • Whether validation also runs on direct server-side calls or only across the RPC boundary.

Refs #507

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the actionable context in #507 and its linked server-function constraint discussion, then review the existing query and action APIs alongside the Standard Schema contract. The open questions about overload shape, multi-argument functions, validation failures, and direct server-side calls must be resolved before implementation is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.