File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @tanstack/react-form-nextjs ' : patch
3+ ' @tanstack/react-form-remix ' : patch
4+ ' @tanstack/react-form-start ' : patch
5+ ---
6+
7+ Fixes bad inference from ` decode-formdata ` 's weird typing of the ` decode ` function, including handling how it incorrectly doesn't handle undefined values for the form info object.
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import type {
1414 ServerFormState ,
1515 UnwrapFormAsyncValidateOrFn ,
1616} from '@tanstack/react-form'
17+ import type { FormDataInfo } from 'decode-formdata'
1718
1819interface CreateServerValidateOptions <
1920 TFormData ,
@@ -75,7 +76,7 @@ export const createServerValidate =
7576 TSubmitMeta
7677 > ,
7778 ) =>
78- async ( formData : FormData , info ?: Parameters < typeof decode > [ 1 ] ) => {
79+ async ( formData : FormData , info ?: FormDataInfo ) => {
7980 const { onServerValidate } = defaultOpts
8081
8182 const runValidator = async ( {
@@ -98,7 +99,9 @@ export const createServerValidate =
9899 } )
99100 }
100101
101- const values = decode ( formData , info ) as never as TFormData
102+ const values = ( info
103+ ? decode ( formData , info )
104+ : decode ( formData ) ) as never as TFormData
102105
103106 const onServerError = ( await runValidator ( {
104107 value : values ,
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import type {
1414 ServerFormState ,
1515 UnwrapFormAsyncValidateOrFn ,
1616} from '@tanstack/react-form'
17+ import type { FormDataInfo } from 'decode-formdata'
1718
1819interface CreateServerValidateOptions <
1920 TFormData ,
@@ -75,7 +76,7 @@ export const createServerValidate =
7576 TSubmitMeta
7677 > ,
7778 ) =>
78- async ( formData : FormData , info ?: Parameters < typeof decode > [ 1 ] ) => {
79+ async ( formData : FormData , info ?: FormDataInfo ) => {
7980 const { onServerValidate } = defaultOpts
8081
8182 const runValidator = async ( {
@@ -98,7 +99,9 @@ export const createServerValidate =
9899 } )
99100 }
100101
101- const values = decode ( formData , info ) as never as TFormData
102+ const values = ( info
103+ ? decode ( formData , info )
104+ : decode ( formData ) ) as never as TFormData
102105
103106 const onServerError = ( await runValidator ( {
104107 value : values ,
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import type {
1717 ServerFormState ,
1818 UnwrapFormAsyncValidateOrFn ,
1919} from '@tanstack/react-form'
20+ import type { FormDataInfo } from 'decode-formdata'
2021
2122interface CreateServerValidateOptions <
2223 TFormData ,
@@ -57,7 +58,7 @@ const serverFn = createServerFn({ method: 'POST' })
5758 . handler ( async ( { data } ) => {
5859 const { formData, info, defaultOpts } = data as {
5960 formData : FormData
60- info ?: Parameters < typeof decode > [ 1 ]
61+ info ?: FormDataInfo
6162 defaultOpts : CreateServerValidateOptions <
6263 any ,
6364 any ,
@@ -97,7 +98,9 @@ const serverFn = createServerFn({ method: 'POST' })
9798
9899 const referer = getRequestHeader ( 'referer' ) !
99100
100- const decodedData = decode ( formData , info ) as never as any
101+ const decodedData = ( info
102+ ? decode ( formData , info )
103+ : decode ( formData ) ) as never as any
101104
102105 const onServerError = ( await runValidator ( {
103106 value : decodedData ,
You can’t perform that action at this time.
0 commit comments