Preview unpublished content
A CMS preview link opens a Route Handler that enables Draft Mode before redirecting to a page.
Next.js 16+ · Function
draftMode lets App Router code inspect or toggle Draft Mode for previewing unpublished CMS content. It is asynchronous and exposes isEnabled, enable(), and disable().
Call the asynchronous function in a Server Component or Route Handler, then use its returned object to inspect isEnabled or toggle the session with enable() and disable(). Enabling sets a bypass cookie so the request avoids cached or pre-rendered results and can retrieve current draft data.
const draft = await draftMode()A promise resolving to an object with isEnabled, enable(), and disable().
draftMode from next/headers; it exposes the controls for the current Draft Mode session.isEnabled in a Server Component when the UI needs to distinguish preview output from published output.enable() in a Route Handler to set the bypass cookie that activates preview behavior.disable() in a Route Handler when the preview session should end before the browser session expires.import { draftMode } from 'next/headers'
import { redirect } from 'next/navigation'
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const slug = searchParams.get('slug') || '/'
const draft = await draftMode()
draft.enable()
redirect(slug)
}This Route Handler enables Draft Mode for the request and redirects the browser to the requested path.
A CMS preview link opens a Route Handler that enables Draft Mode before redirecting to a page.
A Server Component checks isEnabled to render preview-only controls or diagnostics.
A preview-exit endpoint calls disable() to remove the bypass cookie.
draftMode provide?draftMode is asynchronous and returns an object containing isEnabled, enable(), and disable(). Use isEnabled in a Server Component to determine whether the current request is previewing draft content.
Follow-up: Why must a Route Handler or Server Action perform the toggle? The documentation disallows enable() and disable() inside a caching directive scope, so the mutation belongs in a request-handling or action boundary.
Calling enable() sets the __prerender_bypass cookie, which activates Draft Mode for subsequent requests. Calling disable() removes that cookie and ends the mode manually.
Follow-up: What happens to the default session? It ends when the browser closes unless the application explicitly disables it earlier.
Draft Mode bypasses cached or pre-rendered content for the preview request, allowing draft data to be fetched from upstream sources. Other visitors continue receiving the cached or pre-rendered page.
Follow-up: Which caching mechanisms are affected? fetch() skips the Next.js fetch cache, 'use cache' code re-executes without saving results, and unstable_cache reads and writes are bypassed.
Route HandlersServer ComponentsServer Actionsfetch cacheuse cacheunstable_cache