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

Next.js 16+ · Function

after

after schedules work after a response or prerender finishes. Use it for side effects such as logging and analytics that should not block the response.

How it works

Call after with a callback to schedule non-blocking side effects after the response or prerender has finished. It is available in Server Components, Server Functions, Route Handlers, and Proxy, and does not by itself make a route dynamic.

Syntax

after(callback)

Parameters

NameTypeDescription
callback() => void | Promise<void>A callback executed after the response or prerender finishes.

Returns

Schedules the supplied callback; the documentation does not specify a return value.

Key points

  • Use after for work that should happen only once the response or prerender has completed.
  • Logging, analytics, and similar side effects can be moved out of the response's critical path.
  • The API is available across these server-side App Router execution contexts.
  • Using the function does not automatically switch a statically renderable route to dynamic rendering.
  • The callback is subject to the deployment platform's maximum route duration.
  • Use maxDuration when the deployment platform supports configuring the callback timeout.

Common mistakes

  • The callback still runs when rendering fails or when notFound or redirect is called.
  • In serverless deployments, the platform must keep the invocation alive long enough for asynchronous callback work to finish.
  • Do not assume a static page runs the callback only after a user request.

Example: Run post-response work

import { after } from 'next/server'

export default function Page() {
  after(() => {
    console.log('Page rendered')
  })

  return <h1>Dashboard</h1>
}

Schedules logging after the page response or prerender completes.

When to use it

Logging

Record request or rendering information after serving a page without delaying the response.

Analytics

Send usage or conversion events outside the response's critical path.

Deferred side effects

Perform cleanup or other post-response server work within the route duration limit.

Interview questions

QWhat problem does after solve?

after schedules a callback after the response or prerender completes. It is intended for side effects such as logging and analytics that should not delay the response.

Follow-up: Does calling it force dynamic rendering? No. The documentation says it is not a request-time API, so it does not make a route dynamic.

QWhere can after be called?

It can be used in Server Components, including generateMetadata, Server Functions, Route Handlers, and Proxy. The callback runs after the relevant response or prerender finishes.

Follow-up: What happens in a static page? The callback runs at build time or when the page is revalidated.

QWhat execution guarantees and limits apply?

The callback runs even when the response does not complete successfully, including when an error occurs or notFound or redirect is called. Its execution is bounded by the route platform's configured maximum duration.

Follow-up: How can the timeout be adjusted? If supported by the platform, configure the route's maxDuration setting.

  • generateMetadata
  • notFound
  • redirect
  • maxDuration
  • Route Handlers
  • Server Functions
  • Proxy

Source: After. Checked 2026-10-15.