Skip to content

Commit

Permalink
Reproducing previewProps missing
Browse files Browse the repository at this point in the history
How to reproduce:
npm run install
npm run preview
localhost:3000/api/draft?secret=secret-token&slug=preview-page

Gives:
Error: Invariant: previewProps missing previewModeId this should never happen

This repo (except this last commit) comes from this rather similar, but fixed, issue: vercel/next.js#67075

The error is thrown in Nextjs from this line:
https://github.com/vercel/next.js/blob/c839d589abf95d248398848081b8194e0d3aed5c/packages/next/src/server/async-storage/draft-mode-provider.ts#L52
Either because:
- "this" is not defined here
- "this._previewModeId" is not defined here

Running npm run dev and hitting localhost:3000/api/draft?secret=secret-token&slug=preview-page doesn't fail.

The middleware.ts file in this repo is irrellevant but I left it as is.
  • Loading branch information
hsnilsson committed Oct 15, 2024
1 parent fbe85e7 commit be6ca46
Show file tree
Hide file tree
Showing 7 changed files with 5,878 additions and 284 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

#wrangler
.wrangler
3 changes: 3 additions & 0 deletions app/api/disable-draft/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { draftMode } from 'next/headers'

// Specify the Edge Runtime
export const runtime = "edge";

export async function GET(request: Request) {
draftMode().disable()
return new Response('Draft mode is disabled')
Expand Down
3 changes: 3 additions & 0 deletions app/api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { redirect } from 'next/navigation'

// Preview URL: localhost:3000/api/draft?secret=secret-token&slug=preview-page

// Specify the Edge Runtime
export const runtime = "edge";

export async function GET(request: Request) {
// Parse query string parameters
const { searchParams } = new URL(request.url)
Expand Down
5 changes: 5 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';

/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
reactStrictMode: true,
};

if (process.env.NODE_ENV === 'development') {
await setupDevPlatform();
}
export default nextConfig;
Loading

0 comments on commit be6ca46

Please sign in to comment.