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
5214ac15
Unverified
Commit
5214ac15
authored
Feb 25, 2026
by
Zack Tanner
Committed by
GitHub
Feb 25, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[backport]: ensure maxPostponedStateSize is always respected (#90060) (#90471)
Backports: - #90060
parent
c95e357f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
34 deletions
+135
-34
app-page.ts
packages/next/src/build/templates/app-page.ts
+15
-5
base-server.ts
packages/next/src/server/base-server.ts
+22
-29
postponed-request-body.ts
packages/next/src/server/lib/postponed-request-body.ts
+61
-0
layout.tsx
...roduction/app-dir/max-postponed-state-size/app/layout.tsx
+7
-0
page.tsx
.../production/app-dir/max-postponed-state-size/app/page.tsx
+3
-0
max-postponed-state-size.test.ts
...max-postponed-state-size/max-postponed-state-size.test.ts
+21
-0
next.config.js
...roduction/app-dir/max-postponed-state-size/next.config.js
+6
-0
No files found.
packages/next/src/build/templates/app-page.ts
View file @
5214ac15
...
...
@@ -57,6 +57,11 @@ import { ENCODED_TAGS } from '../../server/stream-utils/encoded-tags'
import
{
sendRenderResult
}
from
'../../server/send-payload'
import
{
NoFallbackError
}
from
'../../shared/lib/no-fallback-error.external'
import
{
parseMaxPostponedStateSize
}
from
'../../shared/lib/size-limit'
import
{
getMaxPostponedStateSize
,
getPostponedStateExceededErrorMessage
,
readBodyWithSizeLimit
,
}
from
'../../server/lib/postponed-request-body'
// These are injected by the loader afterwards.
...
...
@@ -227,15 +232,20 @@ export async function handler(
req
.
headers
[
NEXT_RESUME_HEADER
]
===
'1'
&&
req
.
method
===
'POST'
)
{
const
{
maxPostponedStateSize
,
maxPostponedStateSizeBytes
}
=
getMaxPostponedStateSize
(
nextConfig
.
experimental
.
maxPostponedStateSize
)
// Decode the postponed state from the request body, it will come as
// an array of buffers, so collect them and then concat them to form
// the string.
const
body
:
Array
<
Buffer
>
=
[]
for
await
(
const
chunk
of
req
)
{
body
.
push
(
chunk
)
const
body
=
await
readBodyWithSizeLimit
(
req
,
maxPostponedStateSizeBytes
)
if
(
body
===
null
)
{
res
.
statusCode
=
413
res
.
end
(
getPostponedStateExceededErrorMessage
(
maxPostponedStateSize
))
ctx
.
waitUntil
?.(
Promise
.
resolve
())
return
null
}
const
postponed
=
Buffer
.
concat
(
body
)
.
toString
(
'utf8'
)
const
postponed
=
body
.
toString
(
'utf8'
)
addRequestMeta
(
req
,
'postponed'
,
postponed
)
}
...
...
packages/next/src/server/base-server.ts
View file @
5214ac15
...
...
@@ -6,10 +6,7 @@ import type {
import
type
{
MiddlewareRouteMatch
}
from
'../shared/lib/router/utils/middleware-route-matcher'
import
type
{
Params
}
from
'./request/params'
import
type
{
NextConfig
,
NextConfigRuntime
}
from
'./config-shared'
import
{
DEFAULT_MAX_POSTPONED_STATE_SIZE
,
parseMaxPostponedStateSize
,
}
from
'./config-shared'
import
{
parseMaxPostponedStateSize
}
from
'./config-shared'
import
type
{
NextParsedUrlQuery
,
NextUrlWithParsedQuery
,
...
...
@@ -152,6 +149,11 @@ import type { PrerenderedRoute } from '../build/static-paths/types'
import
{
createOpaqueFallbackRouteParams
}
from
'./request/fallback-params'
import
{
RouteKind
}
from
'./route-kind'
import
type
{
ErrorModule
}
from
'./load-default-error-components'
import
{
getMaxPostponedStateSize
,
getPostponedStateExceededErrorMessage
,
readBodyWithSizeLimit
,
}
from
'./lib/postponed-request-body'
export
type
FindComponentsResult
<
NextModule
extends
GenericComponentMod
=
GenericComponentMod
,
...
...
@@ -1056,37 +1058,28 @@ export default abstract class Server<
req
.
headers
[
NEXT_RESUME_HEADER
]
===
'1'
&&
req
.
method
===
'POST'
)
{
// Get the configured max postponed state size.
const
maxPostponedStateSize
=
this
.
nextConfig
.
experimental
.
maxPostponedStateSize
??
DEFAULT_MAX_POSTPONED_STATE_SIZE
const
maxPostponedStateSizeBytes
=
parseMaxPostponedStateSize
(
this
.
nextConfig
.
experimental
.
maxPostponedStateSize
)
if
(
maxPostponedStateSizeBytes
===
undefined
)
{
throw
new
Error
(
'maxPostponedStateSize must be a valid number (bytes) or filesize format string (e.g., "5mb")'
const
{
maxPostponedStateSize
,
maxPostponedStateSizeBytes
}
=
getMaxPostponedStateSize
(
this
.
nextConfig
.
experimental
.
maxPostponedStateSize
)
}
// Decode the postponed state from the request body, it will come as
// an array of buffers, so collect them and then concat them to form
// the string.
const
body
:
Array
<
Buffer
>
=
[]
let
size
=
0
for
await
(
const
chunk
of
req
.
body
)
{
size
+=
Buffer
.
byteLength
(
chunk
)
if
(
size
>
maxPostponedStateSizeBytes
)
{
res
.
statusCode
=
413
const
errorMessage
=
`Postponed state exceeded
${
maxPostponedStateSize
}
limit. `
+
`To configure the limit, see: https://nextjs.org/docs/app/api-reference/config/next-config-js/max-postponed-state-size`
res
.
body
(
errorMessage
).
send
()
return
}
body
.
push
(
chunk
)
const
body
=
await
readBodyWithSizeLimit
(
req
.
body
,
maxPostponedStateSizeBytes
)
if
(
body
===
null
)
{
res
.
statusCode
=
413
res
.
body
(
getPostponedStateExceededErrorMessage
(
maxPostponedStateSize
)
)
.
send
()
return
}
const
postponed
=
Buffer
.
concat
(
body
)
.
toString
(
'utf8'
)
const
postponed
=
body
.
toString
(
'utf8'
)
addRequestMeta
(
req
,
'postponed'
,
postponed
)
}
...
...
packages/next/src/server/lib/postponed-request-body.ts
0 → 100644
View file @
5214ac15
import
{
DEFAULT_MAX_POSTPONED_STATE_SIZE
,
parseMaxPostponedStateSize
,
}
from
'../../shared/lib/size-limit'
import
type
{
SizeLimit
}
from
'../../types'
const
INVALID_MAX_POSTPONED_STATE_SIZE_ERROR_MESSAGE
=
'maxPostponedStateSize must be a valid number (bytes) or filesize format string (e.g., "5mb")'
export
type
PostponedRequestBodyChunk
=
Buffer
|
Uint8Array
|
string
export
function
getMaxPostponedStateSize
(
configuredMaxPostponedStateSize
:
SizeLimit
|
undefined
):
{
maxPostponedStateSize
:
SizeLimit
maxPostponedStateSizeBytes
:
number
}
{
const
maxPostponedStateSize
=
configuredMaxPostponedStateSize
??
DEFAULT_MAX_POSTPONED_STATE_SIZE
const
maxPostponedStateSizeBytes
=
parseMaxPostponedStateSize
(
configuredMaxPostponedStateSize
)
if
(
maxPostponedStateSizeBytes
===
undefined
)
{
throw
new
Error
(
INVALID_MAX_POSTPONED_STATE_SIZE_ERROR_MESSAGE
)
}
return
{
maxPostponedStateSize
,
maxPostponedStateSizeBytes
}
}
export
function
getPostponedStateExceededErrorMessage
(
maxPostponedStateSize
:
SizeLimit
):
string
{
return
(
`Postponed state exceeded
${
maxPostponedStateSize
}
limit. `
+
`To configure the limit, see: https://nextjs.org/docs/app/api-reference/config/next-config-js/max-postponed-state-size`
)
}
function
toBuffer
(
chunk
:
PostponedRequestBodyChunk
):
Buffer
{
return
Buffer
.
isBuffer
(
chunk
)
?
chunk
:
Buffer
.
from
(
chunk
)
}
export
async
function
readBodyWithSizeLimit
(
body
:
AsyncIterable
<
PostponedRequestBodyChunk
>
,
maxBodySizeBytes
:
number
):
Promise
<
Buffer
|
null
>
{
const
chunks
:
Array
<
Buffer
>
=
[]
let
size
=
0
for
await
(
const
chunk
of
body
)
{
const
buffer
=
toBuffer
(
chunk
)
size
+=
buffer
.
byteLength
if
(
size
>
maxBodySizeBytes
)
{
return
null
}
chunks
.
push
(
buffer
)
}
return
Buffer
.
concat
(
chunks
)
}
test/production/app-dir/max-postponed-state-size/app/layout.tsx
0 → 100644
View file @
5214ac15
export
default
function
Layout
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/production/app-dir/max-postponed-state-size/app/page.tsx
0 → 100644
View file @
5214ac15
export
default
function
Page
()
{
return
<
p
>
Hello World
</
p
>
}
test/production/app-dir/max-postponed-state-size/max-postponed-state-size.test.ts
0 → 100644
View file @
5214ac15
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'app-dir - max postponed state size'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should return 413 when next-resume request exceeds max postponed state size'
,
async
()
=>
{
const
res
=
await
next
.
fetch
(
'/'
,
{
method
:
'POST'
,
headers
:
{
'next-action'
:
'abc123'
,
'next-resume'
:
'1'
,
},
body
:
Buffer
.
alloc
(
1025
,
'x'
),
})
expect
(
res
.
status
).
toBe
(
413
)
expect
(
await
res
.
text
()).
toContain
(
'Postponed state exceeded 1 KB limit.'
)
})
})
test/production/app-dir/max-postponed-state-size/next.config.js
0 → 100644
View file @
5214ac15
module
.
exports
=
{
cacheComponents
:
true
,
experimental
:
{
maxPostponedStateSize
:
'1 KB'
,
},
}
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