Skip to content

Preview mode breaks on navigation: “Cannot read properties of undefined (reading 'disable')” when using query() in Next.js 15 #932

@o-lie

Description

@o-lie

Describe the bug

When entering preview mode from WordPress, the initial preview page loads correctly and previewRouteHandler works as expected. However, if I navigate to any other page without exiting preview mode, the application crashes with:
TypeError: Cannot read properties of undefined (reading 'disable')

The error occurs inside Next.js internals (src/server/request/draft-mode.ts) during a query({ params }) call in a single post/page route.

This suggests that draftMode().disable() is being called somewhere without the correct this binding — which was valid in older Next.js versions but breaks in Next.js 15, where draftMode() is now asynchronous.

/api/preview/exit works correctly and exiting preview mode removes the issue.
The crash happens only when navigating in a still-active preview session.

Steps to Reproduce

  1. In WordPress, open any post or page.
  2. Click Preview.
  3. The preview opens correctly in the Next.js frontend (banner displayed).
  4. Without clicking “Exit Preview”, navigate to any other route in the Next.js site (e.g. another post, etc.).
  5. The page crashes with the following error:
    TypeError: Cannot read properties of undefined (reading 'disable')

Screenshots, screen recording, code snippet

No response

Environment information

Device: MacBook Pro

OS: macOS Sonoma

Browser: Chrome 124, Safari 17

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions