Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7ec7159f
Commit
7ec7159f
authored
Aug 01, 2025
by
Ben Gubler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: upgrade Zod from v3 to v4
parent
1c5f64b9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1588 additions
and
941 deletions
+1588
-941
package.json
.github/actions/next-repo-actions/package.json
+1
-1
pnpm-lock.yaml
.github/pnpm-lock.yaml
+1237
-820
package.json
examples/next-forms/package.json
+1
-1
package.json
packages/next/package.json
+2
-2
app-segment-config.ts
...s/next/src/build/segment-config/app/app-segment-config.ts
+6
-8
middleware-config.ts
.../src/build/segment-config/middleware/middleware-config.ts
+17
-11
config-schema.ts
packages/next/src/server/config-schema.ts
+70
-44
pnpm-lock.yaml
pnpm-lock.yaml
+254
-54
No files found.
.github/actions/next-repo-actions/package.json
View file @
7ec7159f
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
"@slack/web-api"
:
"^7.6.0"
,
"@slack/web-api"
:
"^7.6.0"
,
"ai"
:
"^3.4.14"
,
"ai"
:
"^3.4.14"
,
"slack-block-builder"
:
"^2.8.0"
,
"slack-block-builder"
:
"^2.8.0"
,
"zod"
:
"^
3.25.76
"
"zod"
:
"^
4.0.14
"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@vercel/ncc"
:
"^0.38.3"
"@vercel/ncc"
:
"^0.38.3"
...
...
.github/pnpm-lock.yaml
View file @
7ec7159f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
examples/next-forms/package.json
View file @
7ec7159f
...
@@ -14,6 +14,6 @@
...
@@ -14,6 +14,6 @@
"react"
:
"rc"
,
"react"
:
"rc"
,
"react-dom"
:
"rc"
,
"react-dom"
:
"rc"
,
"typescript"
:
"5.3.3"
,
"typescript"
:
"5.3.3"
,
"zod"
:
"^
3.22.
4"
"zod"
:
"^
4.0.1
4"
}
}
}
}
packages/next/package.json
View file @
7ec7159f
...
@@ -353,8 +353,8 @@
...
@@ -353,8 +353,8 @@
"webpack-sources1"
:
"npm:webpack-sources@1.4.3"
,
"webpack-sources1"
:
"npm:webpack-sources@1.4.3"
,
"webpack-sources3"
:
"npm:webpack-sources@3.2.3"
,
"webpack-sources3"
:
"npm:webpack-sources@3.2.3"
,
"ws"
:
"8.2.3"
,
"ws"
:
"8.2.3"
,
"zod"
:
"
3.25.76
"
,
"zod"
:
"
4.0.14
"
,
"zod-validation-error"
:
"
3.4.0
"
"zod-validation-error"
:
"
4.0.1
"
},
},
"keywords"
:
[
"keywords"
:
[
"react"
,
"react"
,
...
...
packages/next/src/build/segment-config/app/app-segment-config.ts
View file @
7ec7159f
...
@@ -73,16 +73,14 @@ export function parseAppSegmentConfig(
...
@@ -73,16 +73,14 @@ export function parseAppSegmentConfig(
route
:
string
route
:
string
):
AppSegmentConfig
{
):
AppSegmentConfig
{
const
parsed
=
AppSegmentConfigSchema
.
safeParse
(
data
,
{
const
parsed
=
AppSegmentConfigSchema
.
safeParse
(
data
,
{
errorMap
:
(
issue
,
ctx
)
=>
{
error
:
(
input
)
=>
{
if
(
issue
.
path
.
length
===
1
&&
issue
.
path
[
0
]
===
'revalidate'
)
{
if
(
input
.
path
?.
length
===
1
&&
input
.
path
[
0
]
===
'revalidate'
)
{
return
{
return
`Invalid revalidate value
${
JSON
.
stringify
(
message
:
`Invalid revalidate value
${
JSON
.
stringify
(
input
.
data
ctx
.
data
)}
on "
${
route
}
", must be a non-negative number or false`
)}
on "
${
route
}
", must be a non-negative number or false`
,
}
}
}
return
{
message
:
ctx
.
defaultError
}
return
undefined
},
},
})
})
...
...
packages/next/src/build/segment-config/middleware/middleware-config.ts
View file @
7ec7159f
...
@@ -8,11 +8,11 @@ const RouteHasSchema = z.discriminatedUnion('type', [
...
@@ -8,11 +8,11 @@ const RouteHasSchema = z.discriminatedUnion('type', [
.
object
({
.
object
({
type
:
z
.
enum
([
'header'
,
'query'
,
'cookie'
]),
type
:
z
.
enum
([
'header'
,
'query'
,
'cookie'
]),
key
:
z
.
string
({
key
:
z
.
string
({
required_
error
:
'key is required when type is header, query or cookie'
,
error
:
'key is required when type is header, query or cookie'
,
}),
}),
value
:
z
value
:
z
.
string
({
.
string
({
invalid_type_
error
:
'value must be a string'
,
error
:
'value must be a string'
,
})
})
.
optional
(),
.
optional
(),
})
})
...
@@ -21,7 +21,7 @@ const RouteHasSchema = z.discriminatedUnion('type', [
...
@@ -21,7 +21,7 @@ const RouteHasSchema = z.discriminatedUnion('type', [
.
object
({
.
object
({
type
:
z
.
literal
(
'host'
),
type
:
z
.
literal
(
'host'
),
value
:
z
.
string
({
value
:
z
.
string
({
required_error
:
'host must have a value'
,
error
:
()
=>
'host must have a value'
,
}),
}),
})
})
.
strict
(),
.
strict
(),
...
@@ -32,23 +32,28 @@ const RouteHasSchema = z.discriminatedUnion('type', [
...
@@ -32,23 +32,28 @@ const RouteHasSchema = z.discriminatedUnion('type', [
*/
*/
export
const
SourceSchema
=
z
export
const
SourceSchema
=
z
.
string
({
.
string
({
required_error
:
'source is required'
,
error
:
(
issue
)
=>
typeof
issue
.
input
!==
'string'
?
'source must be a string'
:
'source is required'
,
})
})
.
max
(
4096
,
'exceeds max built length of 4096 for route'
)
.
max
(
4096
,
'exceeds max built length of 4096 for route'
)
.
superRefine
((
val
,
ctx
)
=>
{
.
superRefine
((
val
,
ctx
)
=>
{
if
(
!
val
.
startsWith
(
'/'
))
{
if
(
!
val
.
startsWith
(
'/'
))
{
return
ctx
.
addIssue
({
ctx
.
issues
.
push
({
code
:
z
.
ZodIssueCode
.
custom
,
code
:
'custom'
,
message
:
`source must start with /`
,
message
:
`source must start with /`
,
input
:
''
,
})
})
}
}
const
{
error
,
regexStr
}
=
tryToParsePath
(
val
)
const
{
error
,
regexStr
}
=
tryToParsePath
(
val
)
if
(
error
||
!
regexStr
)
{
if
(
error
||
!
regexStr
)
{
ctx
.
addIssue
({
ctx
.
issues
.
push
({
code
:
z
.
ZodIssueCode
.
custom
,
code
:
'custom'
,
message
:
`Invalid source '
${
val
}
':
${
error
.
message
}
`
,
message
:
`Invalid source '
${
val
}
':
${
error
.
message
}
`
,
input
:
''
,
})
})
}
}
})
})
...
@@ -66,7 +71,7 @@ const MiddlewareConfigMatcherInputSchema = z.union([
...
@@ -66,7 +71,7 @@ const MiddlewareConfigMatcherInputSchema = z.union([
SourceSchema
,
SourceSchema
,
z
.
array
(
z
.
array
(
z
.
union
([
SourceSchema
,
MiddlewareMatcherInputSchema
],
{
z
.
union
([
SourceSchema
,
MiddlewareMatcherInputSchema
],
{
invalid_type_error
:
'must be an array of strings or middleware matchers'
,
error
:
()
=>
'must be an array of strings or middleware matchers'
,
})
})
),
),
])
])
...
@@ -82,9 +87,10 @@ const GlobSchema = z.string().superRefine((val, ctx) => {
...
@@ -82,9 +87,10 @@ const GlobSchema = z.string().superRefine((val, ctx) => {
try
{
try
{
picomatch
(
val
)
picomatch
(
val
)
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
ctx
.
addIssue
({
ctx
.
issues
.
push
({
code
:
z
.
ZodIssueCode
.
custom
,
code
:
'custom'
,
message
:
`Invalid glob pattern '
${
val
}
':
${
err
.
message
}
`
,
message
:
`Invalid glob pattern '
${
val
}
':
${
err
.
message
}
`
,
input
:
''
,
})
})
}
}
})
})
...
...
packages/next/src/server/config-schema.ts
View file @
7ec7159f
...
@@ -31,6 +31,33 @@ const zSizeLimit = z.custom<SizeLimit>((val) => {
...
@@ -31,6 +31,33 @@ const zSizeLimit = z.custom<SizeLimit>((val) => {
return
false
return
false
})
})
const
functionSchema
=
<
T
>
(
_schema
:
T
)
=>
z
.
custom
<
(
defaultMap
:
ExportPathMap
,
ctx
:
{
dev
:
boolean
dir
:
string
outDir
:
string
|
null
distDir
:
string
buildId
:
string
}
)
=>
ExportPathMap
|
Promise
<
ExportPathMap
>
>
((
val
)
=>
typeof
val
===
'function'
)
const
generateBuildIdSchema
=
<
T
>
(
_schema
:
T
)
=>
z
.
custom
<
()
=>
string
|
Promise
<
string
|
null
>
|
null
>
(
(
val
)
=>
typeof
val
===
'function'
)
const
runAfterProductionCompileSchema
=
<
T
>
(
_schema
:
T
)
=>
z
.
custom
<
(
metadata
:
{
projectDir
:
string
;
distDir
:
string
})
=>
Promise
<
void
>
>
((
val
)
=>
typeof
val
===
'function'
)
const
createAsyncFunctionSchema
=
<
T
>
(
_schema
:
T
)
=>
z
.
custom
<
()
=>
Promise
<
any
>>
((
val
)
=>
typeof
val
===
'function'
)
const
zExportMap
:
zod
.
ZodType
<
ExportPathMap
>
=
z
.
record
(
const
zExportMap
:
zod
.
ZodType
<
ExportPathMap
>
=
z
.
record
(
z
.
string
(),
z
.
string
(),
z
.
object
({
z
.
object
({
...
@@ -271,10 +298,11 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
...
@@ -271,10 +298,11 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
]),
]),
define
:
z
.
record
(
z
.
string
(),
z
.
string
()).
optional
(),
define
:
z
.
record
(
z
.
string
(),
z
.
string
()).
optional
(),
defineServer
:
z
.
record
(
z
.
string
(),
z
.
string
()).
optional
(),
defineServer
:
z
.
record
(
z
.
string
(),
z
.
string
()).
optional
(),
runAfterProductionCompile
:
z
runAfterProductionCompile
:
runAfterProductionCompileSchema
(
.
function
()
z
.
function
({
.
returns
(
z
.
promise
(
z
.
void
()))
output
:
z
.
promise
(
z
.
void
()),
.
optional
(),
})
).
optional
(),
})
})
.
optional
(),
.
optional
(),
compress
:
z
.
boolean
().
optional
(),
compress
:
z
.
boolean
().
optional
(),
...
@@ -340,6 +368,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
...
@@ -340,6 +368,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
.
optional
(),
.
optional
(),
cacheLife
:
z
cacheLife
:
z
.
record
(
.
record
(
z
.
string
(),
z
.
object
({
z
.
object
({
stale
:
z
.
number
().
optional
(),
stale
:
z
.
number
().
optional
(),
revalidate
:
z
.
number
().
optional
(),
revalidate
:
z
.
number
().
optional
(),
...
@@ -538,37 +567,36 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
...
@@ -538,37 +567,36 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
optimizeRouterScrolling
:
z
.
boolean
().
optional
(),
optimizeRouterScrolling
:
z
.
boolean
().
optional
(),
})
})
.
optional
(),
.
optional
(),
exportPathMap
:
z
exportPathMap
:
functionSchema
(
.
function
()
z
.
function
({
.
args
(
input
:
z
.
tuple
([
zExportMap
,
zExportMap
,
z
.
object
({
z
.
object
({
dev
:
z
.
boolean
(),
dev
:
z
.
boolean
(),
dir
:
z
.
string
(),
dir
:
z
.
string
(),
outDir
:
z
.
string
().
nullable
(),
outDir
:
z
.
string
().
nullable
(),
distDir
:
z
.
string
(),
distDir
:
z
.
string
(),
buildId
:
z
.
string
(),
buildId
:
z
.
string
(),
})
}),
)
]),
.
returns
(
z
.
union
([
zExportMap
,
z
.
promise
(
zExportMap
)]))
output
:
z
.
union
([
zExportMap
,
z
.
promise
(
zExportMap
)]),
.
optional
(),
})
generateBuildId
:
z
).
optional
(),
.
function
()
generateBuildId
:
generateBuildIdSchema
(
.
args
()
z
.
function
({
.
returns
(
output
:
z
.
union
([
z
.
union
([
z
.
string
(),
z
.
string
(),
z
.
null
(),
z
.
null
(),
z
.
promise
(
z
.
union
([
z
.
string
(),
z
.
null
()])),
z
.
promise
(
z
.
union
([
z
.
string
(),
z
.
null
()])),
])
])
,
)
}
)
.
optional
(),
)
.
optional
(),
generateEtags
:
z
.
boolean
().
optional
(),
generateEtags
:
z
.
boolean
().
optional
(),
headers
:
z
headers
:
createAsyncFunctionSchema
(
.
function
()
z
.
function
({
.
args
()
output
:
z
.
promise
(
z
.
array
(
zHeader
)),
.
returns
(
z
.
promise
(
z
.
array
(
zHeader
))
)
}
)
.
optional
(),
)
.
optional
(),
htmlLimitedBots
:
z
.
instanceof
(
RegExp
).
optional
(),
htmlLimitedBots
:
z
.
instanceof
(
RegExp
).
optional
(),
httpAgentOptions
:
z
httpAgentOptions
:
z
.
strictObject
({
keepAlive
:
z
.
boolean
().
optional
()
})
.
strictObject
({
keepAlive
:
z
.
boolean
().
optional
()
})
...
@@ -699,16 +727,14 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
...
@@ -699,16 +727,14 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
reactProductionProfiling
:
z
.
boolean
().
optional
(),
reactProductionProfiling
:
z
.
boolean
().
optional
(),
reactStrictMode
:
z
.
boolean
().
nullable
().
optional
(),
reactStrictMode
:
z
.
boolean
().
nullable
().
optional
(),
reactMaxHeadersLength
:
z
.
number
().
nonnegative
().
int
().
optional
(),
reactMaxHeadersLength
:
z
.
number
().
nonnegative
().
int
().
optional
(),
redirects
:
z
redirects
:
createAsyncFunctionSchema
(
.
function
()
z
.
function
({
.
args
()
output
:
z
.
promise
(
z
.
array
(
zRedirect
)),
.
returns
(
z
.
promise
(
z
.
array
(
zRedirect
)))
})
.
optional
(),
).
optional
(),
rewrites
:
z
rewrites
:
createAsyncFunctionSchema
(
.
function
()
z
.
function
({
.
args
()
output
:
z
.
promise
(
.
returns
(
z
.
promise
(
z
.
union
([
z
.
union
([
z
.
array
(
zRewrite
),
z
.
array
(
zRewrite
),
z
.
object
({
z
.
object
({
...
@@ -717,9 +743,9 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
...
@@ -717,9 +743,9 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
fallback
:
z
.
array
(
zRewrite
),
fallback
:
z
.
array
(
zRewrite
),
}),
}),
])
])
)
)
,
)
}
)
.
optional
(),
)
.
optional
(),
// sassOptions properties are unknown besides implementation, use z.any() here
// sassOptions properties are unknown besides implementation, use z.any() here
sassOptions
:
z
sassOptions
:
z
.
object
({
.
object
({
...
...
pnpm-lock.yaml
View file @
7ec7159f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment