Skip to content

Conversation

@theVedanta
Copy link
Contributor

@theVedanta theVedanta commented Apr 20, 2025

Instead of the previous serverValidate function just returning a string, we now return an object:

const serverValidate = createServerValidate({
  ...formOpts,
  onServerValidate: ({ value }) => {
    if (value.age < 12)
      return { age: 'Server validation: You must be at least 12 to sign up' }
  },
})

This then maps to the field-level errors with the setMeta options.

The only reason this is called a preliminary approach is because we are setting the onServer key of the errorMap differently.

Previously, the error map for the form looked like so:

{
  onServer: "You need to be 12 years or older to sign up"
}

Now however, the onServer map is slightly different:

{
  onServer: { age: "You need to be 12 years or older to sign up" }
}

This causes some degree of inconsistency, which is why I would love some feedback on whether we can use some other property (or maybe create our own!) to manage the errors between fields and forms. This would not be a comprehensive property but just a map to sync them back and forth.

NextJS support has been pushed. Remix and Start coming soon.
Support for Array field types will also be done shortly.

Would love your feedback and comments on this approach before I proceed!

Solves the following issue: #1260

@nx-cloud
Copy link

nx-cloud bot commented Apr 20, 2025

View your CI Pipeline Execution ↗ for commit e86715e

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 24s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 25s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-28 03:35:49 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 20, 2025

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1432

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1432

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@1432

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1432

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1432

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@1432

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1432

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@1432

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1432

commit: e86715e

@codecov
Copy link

codecov bot commented Apr 20, 2025

Codecov Report

❌ Patch coverage is 8.33333% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.20%. Comparing base (6892ed0) to head (e86715e).
⚠️ Report is 41 commits behind head on main.

Files with missing lines Patch % Lines
...ages/react-form/src/nextjs/createServerValidate.ts 0.00% 15 Missing and 5 partials ⚠️
packages/form-core/src/FormApi.ts 18.75% 10 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1432      +/-   ##
==========================================
- Coverage   90.35%   89.20%   -1.15%     
==========================================
  Files          38       38              
  Lines        1752     1834      +82     
  Branches      444      474      +30     
==========================================
+ Hits         1583     1636      +53     
- Misses        149      171      +22     
- Partials       20       27       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@theVedanta theVedanta marked this pull request as draft April 20, 2025 19:08
@theVedanta theVedanta changed the title Merging Form-level server errors with Field-level errors feat (form-core): Merging Form-level server errors with Field-level errors Apr 22, 2025
@theVedanta theVedanta marked this pull request as ready for review July 7, 2025 07:29
@vincehi
Copy link

vincehi commented Sep 16, 2025

Hello, do you need a hand to move this branch forward? I would love to see it happen :)

@theVedanta
Copy link
Contributor Author

Hello, do you need a hand to move this branch forward? I would love to see it happen :)

Yeah sure dude, go for it!

@theVedanta
Copy link
Contributor Author

Not sure if this feature is still requested or whether it has been fixed. Don't wanna tag maintainers but this has been dormant for a while, I'd like some insight on how to proceed! @LeCarbonator @harry-whorlow

Copy link
Contributor

@LeCarbonator LeCarbonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay! I'm not too confident in my SSR knowledge, so I'll make sure to give this a try myself. I'll also go through some issues and the reproductions to confirm things.

Hopefully, this initial review should help with some refactoring. It's looking promising!

Since this has been stale for way too long, this will be my focus for now. Feel free to tag me if there's more info you need or a second review. I can also help out with the PR if you'd like.

validationSource: 'form',
})) as UnwrapFormAsyncValidateOrFn<TOnServer> | undefined

console.log('ON SERVER ERROR', onServerError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten console.log

Comment on lines 116 to 126
const errorsArray = onServerErrorVal
? Array.isArray(onServerErrorVal)
? onServerErrorVal.map((err) =>
typeof err === 'object' ? Object.values(err)[0] : err,
)
: [
typeof onServerErrorVal === 'object'
? Object.values(onServerErrorVal)[0]
: onServerErrorVal,
]
: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This double ternary is a bit hard to follow. Please refactor to if statements instead.

const errorsArray = onServerErrorVal
? Array.isArray(onServerErrorVal)
? onServerErrorVal.map((err) =>
typeof err === 'object' ? Object.values(err)[0] : err,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to look into this one. Objects don't inherently have an order, so I'm not sure how consistent taking the first element would be. Perhaps we do this in other places?

The object format you're referring to is the server error fields coming in, right?

Copy link

@jasikpark jasikpark Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually an order of sorts nowadays: https://2ality.com/2015/10/property-traversal-order-es6.html

  1. Integer indices (array-like indices) come first, in ascending numeric order
  2. String keys (non-integer strings) come next, in creation order
  3. Symbol keys come last, in creation

@LeCarbonator
Copy link
Contributor

The merge conflicts appear to be in some of the important diffs, so I'll leave that up to you. I'll see if convenient unit tests could be made for these as we don't want to regress on this.

@theVedanta
Copy link
Contributor Author

Sorry for the long delay! I'm not too confident in my SSR knowledge, so I'll make sure to give this a try myself. I'll also go through some issues and the reproductions to confirm things.

Hopefully, this initial review should help with some refactoring. It's looking promising!

Since this has been stale for way too long, this will be my focus for now. Feel free to tag me if there's more info you need or a second review. I can also help out with the PR if you'd like.

Your help with the PR would be awesome! I'm pretty new to learning about the tanstack ecosystem.
I'll try to make another commit with the fixes.

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

⚠️ No Changeset found

Latest commit: e86715e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

4 participants