DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

Next.js Draft Mode: Why Preview Content Can Stick Around—and How to Turn It Off

Next.js Draft Mode is a browser preview state, not publication. Clear its cookie with an App Router Route Handler, prevent Link prefetch from triggering that route, and secure preview activation.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you can still see unpublished content after finishing a preview, your browser may still be in Next.js Draft Mode. Draft Mode is a preview state—not publication—and its __prerender_bypass cookie affects later requests from that browser. In the App Router, clear it with a Route Handler that awaits draftMode() and calls disable().

Why draft content remains visible after previewing

Next.js Draft Mode lets an application preview draft content from a headless CMS without rebuilding statically generated pages. When a request carries the Draft Mode cookie, Next.js renders the page at request time, allowing it to fetch draft data. As a result, a developer may continue to see unpublished content in the same browser after the editorial preview is over.

As an Amazon Associate I earn from qualifying purchases.

That does not mean the content has been published or that every visitor can see it. The preview state belongs to requests carrying the browser’s __prerender_bypass cookie. By default, the Draft Mode session ends when the browser is closed, or it can be ended explicitly by clearing the cookie. Next.js documents the cookie and session behavior in the draftMode API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Disable Draft Mode in the App Router

In current App Router code, draftMode() is asynchronous. Put the disable call in a Route Handler and call that route when you want to leave preview mode:

import { draftMode } from 'next/headers'

export async function GET() {
  const draft = await draftMode()
  draft.disable()
  return new Response('Draft mode is disabled')
}

Calling disable() deletes the Draft Mode cookie. The handler above uses a GET request, as in the Next.js API reference example; trigger it only when the user intentionally exits preview.

Prevent a Link from clearing the cookie during prefetch

If the disable route is linked with Next.js <Link>, set prefetch={false}. Otherwise, Next.js may prefetch the route and invoke it before the user chooses to leave preview, clearing the cookie unexpectedly.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
<Link href="/api/disable-draft" prefetch={false}>
  Exit preview
</Link>

Secure the route that enables Draft Mode

Disabling preview fixes a stale preview session; secure activation prevents unauthorized users from creating one. Next.js’s App Router guide recommends checking a shared secret, requiring a content slug, verifying that the content exists, and enabling Draft Mode only after those checks succeed. Resolve the redirect destination from the verified CMS record rather than redirecting to an untrusted query-string value such as slug, which could enable an open redirect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Compare the supplied secret with the secret shared by the app and CMS.
  2. Require a content identifier and look up that item in the CMS.
  3. Reject the request if the secret is invalid, the identifier is missing, or the content does not exist.
  4. Enable Draft Mode, then redirect to the path resolved from the verified CMS record.

Next.js changes the built-in bypass cookie value each time next build runs, making the value harder to guess. That is not a substitute for protecting the route that issues the cookie with a secret and content validation. See the Next.js Draft Mode guide for the documented activation pattern.

App Router and Pages Router use different APIs

Do not copy a Pages Router example into an App Router application. The documented APIs and rendering paths differ:

Router Draft Mode API How to disable it Cache guidance
App Router draftMode() from next/headers In a Route Handler, await draftMode() and call disable(). Request state is read with the App Router API; cache behavior may also depend on application and deployment configuration.
Pages Router Legacy Pages Router APIs, including res.setDraftMode and the getStaticProps/getServerSideProps context Use the documented setDraftMode({ enable: false }) API. The Pages Router guide warns not to set Cache-Control when using Draft Mode; consult its ISR guidance.

The Pages Router details are in the separate Next.js Pages Router Draft Mode guide. The API reference says Draft Mode was introduced in Next.js v13.4.0 and that draftMode became async in v15.0.0-RC; synchronous access in Next.js 15 was retained for backward compatibility but is deprecated. Follow the API for the router and version your application actually uses.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What to check if draft content still appears

If the App Router disable handler ran but the page still shows a draft, trace the request and data path rather than assuming a cache header will fix it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Check whether the browser still has the __prerender_bypass cookie and whether the disable route actually ran.
  • Confirm which CMS data source the page uses in preview mode versus published mode.
  • Investigate application and deployment caching for the affected page and data. The outcome depends on the implementation and host; the Next.js documentation does not establish one universal host-specific result.
  • Do not assume that adding a generic Cache-Control header bypasses Draft Mode. The Pages Router guide specifically warns that Draft Mode cannot bypass that header and points to ISR guidance instead.

In code using cache scopes, request APIs such as draftMode() cannot be accessed inside a 'use cache' function. Read request state outside the cached function and pass the needed value in. Next.js explains this constraint in its request-information access guidance.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.