Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/lucky-beds-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/react-form-nextjs': patch
'@tanstack/react-form-remix': patch
'@tanstack/react-form-start': patch
---

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.
7 changes: 5 additions & 2 deletions packages/react-form-nextjs/src/createServerValidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
ServerFormState,
UnwrapFormAsyncValidateOrFn,
} from '@tanstack/react-form'
import type { FormDataInfo } from 'decode-formdata'

interface CreateServerValidateOptions<
TFormData,
Expand Down Expand Up @@ -75,7 +76,7 @@ export const createServerValidate =
TSubmitMeta
>,
) =>
async (formData: FormData, info?: Parameters<typeof decode>[1]) => {
async (formData: FormData, info?: FormDataInfo) => {
const { onServerValidate } = defaultOpts

const runValidator = async ({
Expand All @@ -98,7 +99,9 @@ export const createServerValidate =
})
}

const values = decode(formData, info) as never as TFormData
const values = (info
? decode(formData, info)
: decode(formData)) as never as TFormData

const onServerError = (await runValidator({
value: values,
Expand Down
7 changes: 5 additions & 2 deletions packages/react-form-remix/src/createServerValidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
ServerFormState,
UnwrapFormAsyncValidateOrFn,
} from '@tanstack/react-form'
import type { FormDataInfo } from 'decode-formdata'

interface CreateServerValidateOptions<
TFormData,
Expand Down Expand Up @@ -75,7 +76,7 @@ export const createServerValidate =
TSubmitMeta
>,
) =>
async (formData: FormData, info?: Parameters<typeof decode>[1]) => {
async (formData: FormData, info?: FormDataInfo) => {
const { onServerValidate } = defaultOpts

const runValidator = async ({
Expand All @@ -98,7 +99,9 @@ export const createServerValidate =
})
}

const values = decode(formData, info) as never as TFormData
const values = (info
? decode(formData, info)
: decode(formData)) as never as TFormData

const onServerError = (await runValidator({
value: values,
Expand Down
7 changes: 5 additions & 2 deletions packages/react-form-start/src/createServerValidate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
ServerFormState,
UnwrapFormAsyncValidateOrFn,
} from '@tanstack/react-form'
import type { FormDataInfo } from 'decode-formdata'

interface CreateServerValidateOptions<
TFormData,
Expand Down Expand Up @@ -57,7 +58,7 @@ const serverFn = createServerFn({ method: 'POST' })
.handler(async ({ data }) => {
const { formData, info, defaultOpts } = data as {
formData: FormData
info?: Parameters<typeof decode>[1]
info?: FormDataInfo
defaultOpts: CreateServerValidateOptions<
any,
any,
Expand Down Expand Up @@ -97,7 +98,9 @@ const serverFn = createServerFn({ method: 'POST' })

const referer = getRequestHeader('referer')!

const decodedData = decode(formData, info) as never as any
const decodedData = (info
? decode(formData, info)
: decode(formData)) as never as any

const onServerError = (await runValidator({
value: decodedData,
Expand Down