Skip to content

Commit

Permalink
fix applications using Next.js v.14.2.0-canary.18 and up (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz authored Mar 22, 2024
1 parent 8da9da2 commit 53cb762
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .changeset/sour-jeans-kneel.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 53cb762

Please sign in to comment.