TanStack / TanStack/router

conflicting validated input values when piping data through middleware validators with differing schemas

Open
#3,783 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Start

Describe the bug

The output of zod parsing removes any extra keys from the data input and means that any subsequent validators cannot successfully validate the body. This can be worked around by putting .passthrough() at the end of the zod schema. The types for calling the serverFn imply that this is not the case as it has the inputs merged for the data field.

Your Example Website or App

https://codesandbox.io/p/devbox/sleepy-rubin-9qd7w2

Steps to Reproduce the Bug or Issue

Run pnpm dev
Navigate to the home page.

Expected behavior

As a user I would expect that I am able to validate input on the middleware, but then also be able to validate additional inputs on the serverFn, for example if I need to validate that a user can access an organisation, i would put the organisation id in the middleware, validate that they can access it and put the organisation into the context, then validate the serverFn specific inputs in the serverFn. This assumption is backed up by how the types get merged by the middleware and the serverFn.

Screenshots or Videos

No response

Platform
  • OS: Linux
  • Browser: Firefox
  • Version: 1.114.22
Additional context

No response

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 with the linked CodeSandbox reproduction and run pnpm dev, then trace how middleware validators and the serverFn validator process the same input. Done means middleware validation can coexist with serverFn validation when the schemas contain different fields, without requiring .passthrough().

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.