Skip to main content
Draft Mode lets you preview unpublished content from a headless CMS without rebuilding your entire site. It switches statically generated pages to dynamic rendering for the duration of the preview session.

How it works

When Draft Mode is enabled, Next.js sets a __prerender_bypass cookie. Subsequent requests containing this cookie render pages dynamically at request time instead of serving cached static output.

Setup

1

Create a draft Route Handler

Create a Route Handler that enables Draft Mode:
Visit /api/draft to test—check the browser’s DevTools for the Set-Cookie response header with __prerender_bypass.
2

Secure the Route Handler with a secret token

In production, secure your draft URL with a secret token shared between your Next.js app and your headless CMS:
Configure your CMS to use a draft URL like:
3

Read draft mode in your page

Check draftMode().isEnabled to switch between draft and production data sources:
When isEnabled is true, data is fetched at request time rather than at build time.

Disabling draft mode

Create an endpoint to disable draft mode:

Checking draft mode status

You can read the draft mode status in any Server Component:
Draft Mode is incompatible with static exports since it requires dynamic rendering per request.