Free tools Windows power users keep installed

One-click scans. No signup required.

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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

If your Next.js browser session still shows unpublished content after you finish previewing, disable Draft Mode to remove its __prerender_bypass cookie. In the current App Router, do that in a Route Handler with await draftMode() followed by draft.disable(). This clears preview mode for that browser; it does not publish the content or make it visible to other visitors.

Why unpublished content can remain visible

Next.js Draft Mode is a preview mechanism for viewing draft content from a headless CMS without rebuilding statically generated pages. When a request carries the Draft Mode cookie, Next.js can render the page at request time and fetch draft data. If you leave Draft Mode enabled, later requests from that browser can continue to use the preview behavior, so the page may still show a draft after you think the preview is over. That does not mean the content has been published or that every visitor can see it. Next.js explains Draft Mode for the App Router.

By default, the Draft Mode session ends when the browser closes. To end it sooner, explicitly disable the mode. The Next.js draftMode API reference describes the cookie behavior: enable() sets __prerender_bypass, while disable() deletes it.

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

Disable Draft Mode in the App Router

Create a Route Handler that calls disable(), then request that route from the browser where you want to leave preview mode. The current API is asynchronous, so await draftMode() before calling the method.

import { draftMode } from 'next/headers'

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

For example, save this handler as app/api/disable-draft/route.ts, then navigate to /api/disable-draft in the previewing browser. The route’s path is an example; use the path where you created your handler. After it runs, reload the content page to check the non-preview result.

If you use a Next.js Link

If a <Link> points to the disable endpoint, set prefetch={false}. Link prefetching can request the endpoint before the user clicks, clearing the cookie unexpectedly. For example:

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 preview

Disabling Draft Mode is only half of a safe preview flow. The route that enables it should not accept arbitrary requests that can activate preview or redirect a visitor to an untrusted destination. Next.js recommends checking a shared secret between your app and CMS, requiring a content slug, verifying that the content exists, and enabling Draft Mode only after those checks pass. Redirect to the path resolved from the verified CMS record—not to a raw query-string value such as slug, which can create an open redirect vulnerability. See the Next.js Draft Mode guide for the activation flow.

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

Next.js changes the built-in bypass cookie value each time next build runs, which the API reference says prevents the value from being guessed. That is not a substitute for protecting the activation endpoint with a secret and validating the requested content.

App Router and Pages Router use different APIs

Do not mix examples from the two router systems. The App Router uses the asynchronous draftMode() API in a Route Handler. Draft Mode was introduced in Next.js 13.4.0; the API became asynchronous in the Next.js 15.0.0 release candidate. Next.js 15 retained synchronous access temporarily for backward compatibility, but it is deprecated. Use the awaited form in current App Router code.

The Pages Router has a separate API and data-fetching model. Its documented disabling method is res.setDraftMode({ enable: false }), used with Pages Router request/response handling rather than the App Router’s draftMode().disable(). Consult the Pages Router Draft Mode guide instead of copying an App Router handler into a Pages Router project.

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

If you still see draft content after disabling it

Check the request path in order: confirm the disable endpoint ran in the same browser, verify that the __prerender_bypass cookie is gone, and reload the page. If the cookie is cleared but the content remains, investigate which data source the page uses in preview and published modes, then review application and deployment caching. The behavior of a particular hosting cache is not established by the Next.js documentation cited here.

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

Do not assume adding a generic Cache-Control header will bypass Draft Mode. The Pages Router guide warns against setting that header when using Draft Mode because the mode cannot bypass it, and points to Incremental Static Regeneration (ISR) guidance instead. For App Router 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 in the value it needs; see the Next.js request-information 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.