Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f43e9a0
test: add failing test for merge-form behavior
crutchcorn Nov 30, 2025
44e6f2b
chore: attempt 1
crutchcorn Nov 30, 2025
fa25c4c
chore: attempt 2
crutchcorn Nov 30, 2025
6e713a2
chore: attempt 3
crutchcorn Nov 30, 2025
67e0820
chore: attempt 4
crutchcorn Nov 30, 2025
7782f56
chore: attempt 5
crutchcorn Nov 30, 2025
bf888d6
CHORE!: REMOVE THIS ATTEMP
crutchcorn Nov 30, 2025
20db3db
chore: attempt 6
crutchcorn Nov 30, 2025
464a129
WIP: TO REVERT: Temp replace Next action with failing usage
crutchcorn Nov 30, 2025
c293607
chore: add logs
crutchcorn Nov 30, 2025
9a62257
chore: attempt 7
crutchcorn Dec 1, 2025
c70194a
chore: demo working version
crutchcorn Dec 1, 2025
4bf648a
feat: move to useMerge away from useTransform
crutchcorn Dec 1, 2025
106789f
chore: fix remix and start
crutchcorn Dec 1, 2025
b91b88d
ci: apply automated fixes and generate docs
autofix-ci[bot] Dec 1, 2025
3c369df
Merge branch 'main' into fix-ssr-issue
crutchcorn Dec 8, 2025
88d0d7c
chore: attempt 8
crutchcorn Dec 8, 2025
2446858
chore: attempt to fix Start and Remix as well
crutchcorn Dec 8, 2025
322979e
ci: apply automated fixes and generate docs
autofix-ci[bot] Dec 8, 2025
cfedaf7
Merge branch 'main' into fix-ssr-issue
crutchcorn Jan 28, 2026
85a4e49
chore: add our own deepCopy impl
crutchcorn Jan 28, 2026
1c651e7
ci: apply automated fixes and generate docs
autofix-ci[bot] Jan 28, 2026
388b78e
chore: fix eslint
crutchcorn Jan 28, 2026
9e0b1b9
Merge branch 'fix-ssr-issue' of https://github.com/TanStack/form into…
crutchcorn Jan 28, 2026
a693662
chore: fix more issues
crutchcorn Jan 28, 2026
d03973e
ci: apply automated fixes and generate docs
autofix-ci[bot] Jan 28, 2026
94ab7c2
fix: JS disabled SSR envs should work now
crutchcorn Jan 28, 2026
838db1f
Merge branch 'fix-ssr-issue' of https://github.com/TanStack/form into…
crutchcorn Jan 28, 2026
e882d4f
test: add tests for SSR mergeForm
crutchcorn Jan 30, 2026
e830a7d
fix: handle field errors from transform
crutchcorn Jan 30, 2026
294c08a
chore: remove log
crutchcorn Jan 30, 2026
23560c6
Merge branch 'main' into fix-ssr-issue
crutchcorn Jan 30, 2026
30a5767
chore: fix props
crutchcorn Jan 30, 2026
802eb79
test: add React unit test
crutchcorn Jan 30, 2026
4b80589
chore: refactor to remove setTimeout
crutchcorn Jan 30, 2026
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
36 changes: 36 additions & 0 deletions examples/react/next-server-actions-zod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions examples/react/next-server-actions-zod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
6 changes: 6 additions & 0 deletions examples/react/next-server-actions-zod/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
}

export default nextConfig
24 changes: 24 additions & 0 deletions examples/react/next-server-actions-zod/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@tanstack/form-example-react-next-server-actions-zod",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"_test:types": "tsc"
},
"dependencies": {
"@tanstack/react-form-nextjs": "^1.28.0",
"@tanstack/react-store": "^0.8.0",
"next": "16.0.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/node": "^24.1.0",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"typescript": "5.8.2"
}
}
39 changes: 39 additions & 0 deletions examples/react/next-server-actions-zod/src/app/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use server'

import {
ServerValidateError,
createServerValidate,
} from '@tanstack/react-form-nextjs'
import { z } from 'zod'
import { formOpts } from './shared-code'

const schema = z.object({
age: z.coerce.number().min(12),
firstName: z.string(),
})

const serverValidate = createServerValidate({
...formOpts,
onServerValidate: schema,
})

export default async function someAction(prev: unknown, formData: FormData) {
try {
const validatedData = await serverValidate(formData)
console.log('validatedData', validatedData)
// Persist the form data to the database
// await sql`
// INSERT INTO users (name, email, password)
// VALUES (${validatedData.name}, ${validatedData.email}, ${validatedData.password})
// `
} catch (e) {
if (e instanceof ServerValidateError) {
return e.formState
}

// Some other error occurred while validating your form
throw e
}

// Your form has successfully validated!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use client'

import { useActionState } from 'react'
import {
initialFormState,
mergeForm,
useForm,
useTransform,
} from '@tanstack/react-form-nextjs'
import { z } from 'zod'
import someAction from './action'
import { formOpts } from './shared-code'

export const ClientComp = () => {
const [state, action] = useActionState(someAction, initialFormState)

const form = useForm({
...formOpts,
transform: useTransform(
(baseForm) => mergeForm(baseForm, state ?? {}),
[state],
),
})

return (
<form action={action as never} onSubmit={() => form.handleSubmit()}>
<form.Field
name="age"
validators={{
onChange: z.coerce.number().min(8),
}}
>
{(field) => {
return (
<div>
<input
name="age"
type="number"
value={field.state.value}
onChange={(e) => field.handleChange(e.target.valueAsNumber)}
/>
{field.state.meta.errors.map((error) => (
<p key={error?.message ?? ''}>{error?.message}</p>
))}
</div>
)
}}
</form.Field>
<form.Subscribe
selector={(formState) => [formState.canSubmit, formState.isSubmitting]}
>
{([canSubmit, isSubmitting]) => (
<button type="submit" disabled={!canSubmit}>
{isSubmitting ? '...' : 'Submit'}
</button>
)}
</form.Subscribe>
</form>
)
}
18 changes: 18 additions & 0 deletions examples/react/next-server-actions-zod/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Metadata } from 'next'

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
9 changes: 9 additions & 0 deletions examples/react/next-server-actions-zod/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ClientComp } from './client-component'

export default function Home() {
return (
<>
<ClientComp />
</>
)
}
8 changes: 8 additions & 0 deletions examples/react/next-server-actions-zod/src/app/shared-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { formOptions } from '@tanstack/react-form-nextjs'

export const formOpts = formOptions({
defaultValues: {
firstName: '',
age: 0,
},
})
30 changes: 30 additions & 0 deletions examples/react/next-server-actions-zod/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion examples/react/next-server-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"@tanstack/react-form-nextjs": "^1.28.0",
"@tanstack/react-store": "^0.8.0",
"next": "15.5.3",
"next": "16.0.5",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
10 changes: 8 additions & 2 deletions examples/react/next-server-actions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules"]
}
Loading
Loading