Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Next.js 16+ · Const

maxDuration

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.

Since
13.4.10

How it works

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.

Syntax

export const maxDuration = 5

Parameters

NameTypeDescription
maxDurationnumberMaximum server-side execution time for the route segment, measured in seconds.

Returns

No runtime return value; this is a route segment configuration export.

Key points

  • Use the option to declare a maximum server-side execution duration for a route segment.
  • The setting is a named export whose value is a number, expressed in seconds.
  • It can be declared in a layout, page, or route file.
  • The option was introduced in Next.js 13.4.10 and remains available in current App Router documentation.

Common mistakes

  • The deployment platform determines how the configured value becomes an actual execution limit.
  • For Server Actions, export the setting from the page rather than relying on a nested segment.

Example: page.tsx

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.

When to use it

Limit page execution time

A server-rendered page performs work that must finish within a known platform timeout.

Bound route-handler duration

A route handler processes a request with a bounded execution budget.

Configure Server Action timeout

Server Actions on a page need a different default timeout.

Interview questions

QWhat does 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.

QHow do you declare 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.

QHow does 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 Config
  • Server Actions
  • after

Source: maxDuration. Checked 2026-10-15.