Skip to content

Commit 9f6258f

Browse files
authored
chore: update zod to v4.4.3 (#7441)
* chore: update zod to v4.4.3 * fix(start): preserve route path defaults * fix(examples): resolve zod 4 build failures
1 parent fa48ea8 commit 9f6258f

184 files changed

Lines changed: 647 additions & 694 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/router/how-to/arrays-objects-dates-search-params.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const dashboardSchema = z.object({
165165
columns: z.number().min(1).max(6).default(3),
166166
showDetails: z.boolean().default(false),
167167
})
168-
.default({}),
168+
.prefault({}),
169169

170170
filters: z
171171
.object({
@@ -176,9 +176,9 @@ const dashboardSchema = z.object({
176176
before: z.string().optional(),
177177
})
178178
.optional(),
179-
metadata: z.record(z.string()).optional(), // Dynamic object keys
179+
metadata: z.record(z.string(), z.string()).optional(), // Dynamic object keys
180180
})
181-
.default({}),
181+
.prefault({}),
182182
})
183183

184184
export const Route = createFileRoute('/dashboard')({
@@ -459,7 +459,7 @@ const analyticsSchema = z.object({
459459
gap: z.number().default(16),
460460
responsive: z.boolean().default(true),
461461
})
462-
.default({}),
462+
.prefault({}),
463463

464464
timeRange: z
465465
.object({
@@ -471,9 +471,9 @@ const analyticsSchema = z.object({
471471
})
472472
.optional(),
473473
})
474-
.default({}),
474+
.prefault({}),
475475
})
476-
.default({}),
476+
.prefault({}),
477477
})
478478

479479
export const Route = createFileRoute('/analytics')({

‎docs/router/how-to/setup-basic-search-params.md‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { createFileRoute } from '@tanstack/react-router'
1313
import { z } from 'zod'
1414

1515
const productSearchSchema = z.object({
16-
page: fallback(z.number(), 1).default(1),
17-
category: fallback(z.string(), 'all').default('all'),
18-
showSale: fallback(z.boolean(), false).default(false),
16+
page: z.number().default(1).catch(1),
17+
category: z.string().default('all').catch('all'),
18+
showSale: z.boolean().default(false).catch(false),
1919
})
2020

2121
export const Route = createFileRoute('/products')({
@@ -100,7 +100,6 @@ Start by identifying what search parameters your route needs:
100100

101101
```tsx
102102
import { z } from 'zod'
103-
import { fallback } from '@tanstack/zod-adapter'
104103

105104
const shopSearchSchema = z.object({
106105
// Pagination
@@ -238,7 +237,7 @@ const dashboardSchema = z.object({
238237
status: z.enum(['active', 'inactive']).optional(),
239238
type: z.string().optional(),
240239
})
241-
.default({}),
240+
.prefault({}),
242241
})
243242
```
244243

@@ -333,7 +332,7 @@ export const Route = createFileRoute('/example')({
333332

334333
### Problem: Search Parameters Cause TypeScript Errors
335334

336-
**Cause:** Missing or incorrect schema definition with Zod v3.
335+
**Cause:** Missing or incorrect schema definition.
337336

338337
**Solution:** Ensure your schema covers all search parameters and use proper types:
339338

@@ -345,12 +344,12 @@ export const Route = createFileRoute('/page')({
345344

346345
// ✅ Complete schema with proper validation
347346
const searchSchema = z.object({
348-
page: fallback(z.number(), 1).default(1),
349-
category: fallback(z.string(), 'all').default('all'),
347+
page: z.number().default(1).catch(1),
348+
category: z.string().default('all').catch('all'),
350349
})
351350

352351
export const Route = createFileRoute('/page')({
353-
validateSearch: zodValidator(searchSchema),
352+
validateSearch: searchSchema,
354353
component: MyPage,
355354
})
356355
```
@@ -382,7 +381,7 @@ const schema = z.object({
382381
```tsx
383382
const schema = z.object({
384383
// Required with default (navigation can omit, but always present in component)
385-
page: fallback(z.number(), 1).default(1),
384+
page: z.number().default(1).catch(1),
386385

387386
// Truly optional (can be undefined in component)
388387
searchTerm: z.string().optional(),
@@ -397,8 +396,8 @@ const schema = z.object({
397396

398397
```tsx
399398
const schema = z.object({
400-
filters: fallback(
401-
z.object({
399+
filters: z
400+
.object({
402401
status: z.enum(['active', 'inactive']).optional(),
403402
tags: z.string().array().optional(),
404403
dateRange: z
@@ -407,9 +406,9 @@ const schema = z.object({
407406
end: z.string().pipe(z.coerce.date()),
408407
})
409408
.optional(),
410-
}),
411-
{},
412-
).default({}),
409+
})
410+
.prefault({})
411+
.catch({}),
413412
})
414413
```
415414

‎e2e/react-router/basic-esbuild-file-based/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
"@tanstack/react-router": "workspace:^",
1414
"@tanstack/react-router-devtools": "workspace:^",
1515
"@tanstack/router-plugin": "workspace:^",
16-
"@tanstack/zod-adapter": "workspace:^",
1716
"react": "^19.0.0",
1817
"react-dom": "^19.0.0",
1918
"redaxios": "^0.5.1",
20-
"zod": "^3.24.2"
19+
"zod": "^4.4.3"
2120
},
2221
"devDependencies": {
2322
"@playwright/test": "^1.50.1",

‎e2e/react-router/basic-esbuild-file-based/src/routes/(group)/_layout.inside.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { createFileRoute, getRouteApi, useSearch } from '@tanstack/react-router'
22
import { z } from 'zod'
3-
import { zodValidator } from '@tanstack/zod-adapter'
43

54
const routeApi = getRouteApi('/(group)/_layout/inside')
65

76
export const Route = createFileRoute('/(group)/_layout/inside')({
8-
validateSearch: zodValidator(z.object({ hello: z.string().optional() })),
7+
validateSearch: z.object({ hello: z.string().optional() }),
98
component: () => {
109
const searchViaHook = useSearch({ from: '/(group)/_layout/inside' })
1110
const searchViaRouteHook = Route.useSearch()
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import { z } from 'zod'
3-
import { zodValidator } from '@tanstack/zod-adapter'
43

54
export const Route = createFileRoute('/(group)/lazyinside')({
6-
validateSearch: zodValidator(z.object({ hello: z.string().optional() })),
5+
validateSearch: z.object({ hello: z.string().optional() }),
76
})

‎e2e/react-router/basic-file-based-code-splitting/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"react": "^19.0.0",
1919
"react-dom": "^19.0.0",
2020
"tailwindcss": "^4.2.2",
21-
"zod": "^3.24.2"
21+
"zod": "^4.4.3"
2222
},
2323
"devDependencies": {
2424
"@playwright/test": "^1.50.1",

‎e2e/react-router/basic-file-based/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
"@tanstack/react-router": "workspace:^",
1717
"@tanstack/react-router-devtools": "workspace:^",
1818
"@tanstack/router-plugin": "workspace:^",
19-
"@tanstack/zod-adapter": "workspace:^",
2019
"react": "^19.0.0",
2120
"react-dom": "^19.0.0",
2221
"redaxios": "^0.5.1",
2322
"tailwindcss": "^4.2.2",
24-
"zod": "^3.24.2"
23+
"zod": "^4.4.3"
2524
},
2625
"devDependencies": {
2726
"@playwright/test": "^1.50.1",

‎e2e/react-router/basic-file-based/src/routes/(another-group)/onlyrouteinside.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import { getRouteApi, useSearch } from '@tanstack/react-router'
33
import { z } from 'zod'
4-
import { zodValidator } from '@tanstack/zod-adapter'
54

65
const routeApi = getRouteApi('/(another-group)/onlyrouteinside')
76

87
export const Route = createFileRoute('/(another-group)/onlyrouteinside')({
9-
validateSearch: zodValidator(z.object({ hello: z.string().optional() })),
8+
validateSearch: z.object({ hello: z.string().optional() }),
109
component: () => {
1110
const searchViaHook = useSearch({
1211
from: '/(another-group)/onlyrouteinside',

‎e2e/react-router/basic-file-based/src/routes/(group)/_layout.insidelayout.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import { getRouteApi, useSearch } from '@tanstack/react-router'
33
import { z } from 'zod'
4-
import { zodValidator } from '@tanstack/zod-adapter'
54

65
const routeApi = getRouteApi('/(group)/_layout/insidelayout')
76

87
export const Route = createFileRoute('/(group)/_layout/insidelayout')({
9-
validateSearch: zodValidator(z.object({ hello: z.string().optional() })),
8+
validateSearch: z.object({ hello: z.string().optional() }),
109
component: () => {
1110
const searchViaHook = useSearch({ from: '/(group)/_layout/insidelayout' })
1211
const searchViaRouteHook = Route.useSearch()

‎e2e/react-router/basic-file-based/src/routes/(group)/inside.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import { getRouteApi, useSearch } from '@tanstack/react-router'
33
import { z } from 'zod'
4-
import { zodValidator } from '@tanstack/zod-adapter'
54

65
const routeApi = getRouteApi('/(group)/inside')
76

87
export const Route = createFileRoute('/(group)/inside')({
9-
validateSearch: zodValidator(z.object({ hello: z.string().optional() })),
8+
validateSearch: z.object({ hello: z.string().optional() }),
109
component: () => {
1110
const searchViaHook = useSearch({ from: '/(group)/inside' })
1211
const searchViaRouteHook = Route.useSearch()

0 commit comments

Comments
 (0)