diff --git a/.changeset/hot-ducks-burn.md b/.changeset/hot-ducks-burn.md new file mode 100644 index 000000000..a2b6d1ced --- /dev/null +++ b/.changeset/hot-ducks-burn.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +Fix preview mode in cache interceptor diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index 70dd083f8..7b616d5ca 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -185,6 +185,17 @@ export async function cacheInterceptor( 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; + } // We localize the path in case i18n is enabled let localizedPath = localizePath(event); // If using basePath we need to remove it from the path