Skip to content
Source
Sign inSign up
TanStack/router

fix: extract props from validator issues #3708

Closedjkazimierczak(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/3708/headopened

Changes Summary

Replaces naive JSON serialization of validator issues by extracting known properties first, and then serializing extracted values instead of the error itself.

This makes is possible to avoid errors such as validation library having non-serializable errors.

Changes introduced based on the Discord discussion.

How

Introduces utilities provided by Standard Schema to the core package, adds path attribute which schema defines, exports the normalization function and uses it within the execValidator.

Result

The validation result is provided under message key in the error response:

{
  "$error": {
    "message": "{\n  \"root\": [\n    \"must be an object (was a string)\"\n  ],\n  \"issues\": {}\n}",
    "stack": "... error stacktrace ...",
    "cause": { "$undefined": 0 }
  }
}

The validation result is split into two parts - root and issues. root aggregates all validation messages that happened at the root (as explained in When is Issue.path allowed to be undefined? #60), while issues contains all errors for which the path was present.

Future Work

Docs

Maybe it would be good to reword a docs, to mention that validator integrate seamlessly with external validators, that implement Standard Schema?

-Validators also integrate seamlessly with external validators, if you want to use something like Zod.
+Validators also integrate seamlessly with external validators that implement Standard Schema, which includes Zod, Valibot or Arktype among others. Full list of spec-compliant libraries can be found [here](https://github.com/standard-schema/standard-schema?tab=readme-ov-file#what-schema-libraries-implement-the-spec).
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-start-client

    3. yes the docs update as mentioned makes sense!

      we should also add an e2e test for this, ideally using multiple standard schema compatible libraries.

    4. View your CI Pipeline Execution ↗ for commit 997261d1cfa2a51312b4cad45d2d85b64d4fe3d2.

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...❌ Failed5m 37sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded2m 14sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-03-09 20:24:48 UTC

    5. Open in Stackblitz

      More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@3708

      @tanstack/create-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/create-router@3708

      @tanstack/directive-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@3708

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@3708

      @tanstack/create-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/create-start@3708

      @tanstack/history

      npm i https://pkg.pr.new/TanStack/router/@tanstack/history@3708

      @tanstack/react-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@3708

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@3708

      @tanstack/react-router-with-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-with-query@3708

      @tanstack/react-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@3708

      @tanstack/react-start-api-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-api-routes@3708

      @tanstack/react-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@3708

      @tanstack/react-start-config

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-config@3708

      @tanstack/react-start-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@3708

      @tanstack/react-start-router-manifest

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-router-manifest@3708

      @tanstack/react-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@3708

      @tanstack/react-start-server-functions-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-client@3708

      @tanstack/react-start-server-functions-fetcher

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-fetcher@3708

      @tanstack/react-start-server-functions-handler

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-handler@3708

      @tanstack/react-start-server-functions-ssr

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-ssr@3708

      @tanstack/router-cli

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@3708

      @tanstack/router-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@3708

      @tanstack/router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@3708

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@3708

      @tanstack/router-generator

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@3708

      @tanstack/router-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@3708

      @tanstack/router-utils

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@3708

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@3708

      @tanstack/server-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@3708

      @tanstack/solid-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@3708

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@3708

      @tanstack/solid-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@3708

      @tanstack/solid-start-api-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-api-routes@3708

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@3708

      @tanstack/solid-start-config

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-config@3708

      @tanstack/solid-start-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@3708

      @tanstack/solid-start-router-manifest

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-router-manifest@3708

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@3708

      @tanstack/solid-start-server-functions-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-client@3708

      @tanstack/solid-start-server-functions-fetcher

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-fetcher@3708

      @tanstack/solid-start-server-functions-handler

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-handler@3708

      @tanstack/solid-start-server-functions-ssr

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-ssr@3708

      @tanstack/start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start@3708

      @tanstack/start-config

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-config@3708

      @tanstack/start-server-functions-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@3708

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@3708

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@3708

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@3708

      commit: 997261d

    6. Thanks for putting this together! I’m closing this PR because it's quite stale, and validation now runs through start-client-core rather than the file changed here.

      The serialization problem still matters, so I’ve opened #7779 to track a current implementation that covers both server-function and search validation, safe issue normalization, tests, documentation, and bundle-size validation. A fresh PR based on that issue would be welcome :)

Sign in to join this conversation.