-
Notifications
You must be signed in to change notification settings - Fork 176
Closed
Description
The cacheInterceptor in opennextjs-aws does not check for Next.js draft mode cookies
(__prerender_bypass
and __next_preview_data
), causing cached responses to be served even when
preview mode is active. This breaks the Next.js preview functionality for ISR pages.
Steps to Reproduce
- Create an ISR page with
export const revalidate = 300
- Enable draft mode using draftMode().enable()
- Visit the page with preview mode active
- The page shows cached content instead of the latest preview content
Expected Behavior
When Next.js draft mode is active (indicated by __prerender_bypass or __next_preview_data cookies),
the cacheInterceptor should bypass the cache and allow the request to proceed to the Next.js
handler.
Actual Behavior
The cacheInterceptor serves cached content regardless of draft mode status, making preview
functionality unusable for ISR pages.
Proposed Solution
Add a check for Next.js preview mode cookies in the cacheInterceptor:
export async function cacheInterceptor(event) {
if (Boolean(event.headers["next-action"]) ||
Boolean(event.headers["x-prerender-revalidate"]))
return event;
// Check for Next.js preview mode cookies
const cookies = event.headers["cookie"] || ""
const hasPreviewData = cookies.includes("__prerender_bypass") ||
cookies.includes("__next_preview_data");
if (hasPreviewData) {
debug("Preview mode detected, passing through to handler");
return event;
}
// ... rest of the function
}
Environment
- @opennextjs/aws: 3.6.5
- Next.js: 15.3.3
- Deployment: Cloudflare Workers with opennextjs/opennextjs-cloudflare
Metadata
Metadata
Assignees
Labels
No labels