Limit page execution time
A server-rendered page performs work that must finish within a known platform timeout.
Next.js 16+ · Const
maxDuration sets the maximum server-side execution time for a route segment, in seconds. Export it from a layout, page, or route file so the deployment platform can apply the limit.
Set maxDuration to a number of seconds in a layout, page, or route file. The value describes the maximum time allowed for server-side logic in that segment, while the deployment platform applies the actual execution limit. A page-level value also changes the default timeout for Server Actions used by that page.
export const maxDuration = 5| Name | Type | Description |
|---|---|---|
maxDuration | number | Maximum server-side execution time for the route segment, measured in seconds. |
No runtime return value; this is a route segment configuration export.
export const maxDuration = 5
export default function Page() {
return <p>This route may run for up to five seconds.</p>
}Exports a five-second execution limit for this page segment.
A server-rendered page performs work that must finish within a known platform timeout.
A route handler processes a request with a bounded execution budget.
Server Actions on a page need a different default timeout.
maxDuration configure?maxDuration is a route segment configuration option whose value is a number of seconds. It sets the maximum execution time for server-side logic in a layout, page, or route.
Follow-up: What enforces the limit? The deployment platform can read the setting from Next.js build output and apply its own execution constraint.
maxDuration?Export it from a supported segment file, such as page.tsx, using a numeric value: export const maxDuration = 5. The value represents seconds.
Follow-up: Can it be exported from a route handler? Yes; the documented declaration applies to layout, page, and route files.
maxDuration affect Server Actions?The page-level setting changes the default timeout for all Server Actions used on that page. This makes the page the appropriate location when those actions need a different timeout.
Follow-up: Why not set it only in a nested component? The documentation specifically requires page-level placement for changing the Server Actions default.
Route Segment ConfigServer Actionsafter