From 53cb7625b1af14308144765077dea5b56600624f Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 22 Mar 2024 20:32:26 +0000 Subject: [PATCH] fix applications using Next.js v.14.2.0-canary.18 and up (#720) --- .changeset/sour-jeans-kneel.md | 9 +++++++++ .../processVercelFunctions/dedupeEdgeFunctions.ts | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changeset/sour-jeans-kneel.md diff --git a/.changeset/sour-jeans-kneel.md b/.changeset/sour-jeans-kneel.md new file mode 100644 index 000000000..33ab2d98d --- /dev/null +++ b/.changeset/sour-jeans-kneel.md @@ -0,0 +1,9 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +fix applications using Next.js v.14.2.0-canary.18 and up + +In v.14.2.0-canary.18 a simple upstream change in Next.js changes the code that +next-on-pages receives, nullifying a find-and-replace regex that next-on-pages +is currently relying on, update such regex so that it can handle the new code diff --git a/packages/next-on-pages/src/buildApplication/processVercelFunctions/dedupeEdgeFunctions.ts b/packages/next-on-pages/src/buildApplication/processVercelFunctions/dedupeEdgeFunctions.ts index 0e5905d21..f3295237b 100644 --- a/packages/next-on-pages/src/buildApplication/processVercelFunctions/dedupeEdgeFunctions.ts +++ b/packages/next-on-pages/src/buildApplication/processVercelFunctions/dedupeEdgeFunctions.ts @@ -501,12 +501,12 @@ function fixFunctionContents(contents: string): string { // This resolves a critical issue in Next.js 14.0.2 that breaks edge runtime rendering due to the assumption // that the the passed internal request is of type `NodeNextRequest` and never `WebNextRequest`. contents = contents.replace( - /;let{originalRequest:([\w$]+)}=([\w$]+);/gm, - ';let{originalRequest:$1=$2}=$2;', + /;let{originalRequest:([\w$]+)}=([\w$]+)([,;])/gm, + ';let{originalRequest:$1=$2}=$2$3', ); contents = contents.replace( - /const { originalRequest } = ([\w$]+);/gm, - 'const { originalRequest = $1 } = $1;', + /const { originalRequest } = ([\w$]+)([,;])/gm, + 'const { originalRequest = $1 } = $1$3', ); return contents;