Skip to main content

Posts

Showing posts with the label GraphQL

Fixing 'Preview Mode Not Working' in Headless WordPress with Next.js App Router

  There is no frustration quite like the "Preview" button failing in a headless WordPress architecture. You spend hours architecting a perfect Next.js frontend, but when your content editors click   Preview   in the WordPress Admin, they are greeted by a Next.js 404 page, an infinite loading spinner, or worse—the published version of the page instead of their draft. If you are migrating from the Next.js Pages Router to the App Router (Next.js 13+), the old  res.setPreviewData  method is dead. The new  draftMode()  API is powerful but introduces strict architectural requirements regarding cookies, caching, and GraphQL authentication that standard documentation often glosses over. This guide provides a production-grade implementation to fix broken previews in Headless WordPress using the Next.js App Router and WPGraphQL. The Root Cause: Why Previews Fail in the App Router To fix the problem, we must understand the mechanics of the failure. The breakdown ...