Logging
Record request or rendering information after serving a page without delaying the response.
Next.js 16+ · Function
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.
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.
after(callback)| Name | Type | Description |
|---|---|---|
callback | () => void | Promise<void> | A callback executed after the response or prerender finishes. |
Schedules the supplied callback; the documentation does not specify a return value.
after for work that should happen only once the response or prerender has completed.maxDuration when the deployment platform supports configuring the callback timeout.notFound or redirect is called.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.
Record request or rendering information after serving a page without delaying the response.
Send usage or conversion events outside the response's critical path.
Perform cleanup or other post-response server work within the route duration limit.
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.
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.
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.
generateMetadatanotFoundredirectmaxDurationRoute HandlersServer FunctionsProxy