fix: edge rendering failing due to undefined req.originalRequest
#58450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixing a bug
fixes #number
What?
#57815 introduced a bug where edge rendering fails due to the assumption that
req
is only of topNodeNextRequest
and cannot beWebNextRequest
, and therefore assumes thatreq.originalRequest
is defined. In other parts of this file, it correctly falls back to usingreq
when there is nooriginalRequest
property defined on the object. Not falling back results in trying to access a property on undefined;req.originalRequest.socket
, which throws an error and causes rendering to fail when deploying to Cloudflare Pages.next.js/packages/next/src/server/base-server.ts
Lines 916 to 917 in 1ee50b8
Here is an example of how this is treated elsewhere in this file, and how it should be treated where this bug occurs. Note how it falls back to using
req as WebNextRequest
.next.js/packages/next/src/server/base-server.ts
Lines 2314 to 2319 in 1ee50b8
We have had to manually add this patch to @cloudflare/next-on-pages for deployments on Cloudflare Pages to continue working (cloudflare/next-on-pages#534).
I tried to add tests but was unable to actually run any of the test suites on my MacBook or Desktop (WSL), so was unable to do so. This fix is pretty straightforward though and is just doing what is done elsewhere in this file, so hopefully that won't be a blocker.
Why?
How?
Closes NEXT-
Fixes #58265