fix: extract props from validator issues #3708
main fromrefs/pull/3708/head·opened 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
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-start-client
jkazimierczak(GitHub profile, opens in a new tab) changed the title
View your CI Pipeline Execution ↗ for commit 997261d1cfa2a51312b4cad45d2d85b64d4fe3d2.
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 5m 37s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2m 14s View ↗
☁️ Nx Cloud last updated this comment at
2025-03-09 20:24:48UTCOpen in Stackblitz
More templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsc
- tanstack-start-example-basic-static
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-supabase-basic
- tanstack-start-example-trellaux
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
@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@3708commit:
997261dThanks 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.
yes the docs update as mentioned makes sense!
we should also add an e2e test for this, ideally using multiple standard schema compatible libraries.