-
Notifications
You must be signed in to change notification settings - Fork 31k
fix: preserve Request body source in patch-fetch #90886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anthony-schanen
wants to merge
4
commits into
vercel:canary
Choose a base branch
from
anthony-schanen:fix/patch-fetch-request-body-source
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/patch-fetch-request-body/app/api/test-post/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { NextResponse } from 'next/server' | ||
|
|
||
| export async function POST() { | ||
| const req = new Request( | ||
| `http://localhost:${process.env.EXTERNAL_SERVER_PORT}/post`, | ||
| { | ||
| method: 'POST', | ||
| body: JSON.stringify({ key: 'value' }), | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| } | ||
| ) | ||
|
|
||
| const res = await fetch(req) | ||
| const data = await res.json() | ||
| return NextResponse.json({ status: res.status, data }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { ReactNode } from 'react' | ||
| export default function Root({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <html> | ||
| <body>{children}</body> | ||
| </html> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default function Page() { | ||
| return <p>hello world</p> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * @type {import('next').NextConfig} | ||
| */ | ||
| const nextConfig = {} | ||
|
|
||
| module.exports = nextConfig |
53 changes: 53 additions & 0 deletions
53
test/e2e/app-dir/patch-fetch-request-body/patch-fetch-request-body.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { nextTestSetup } from 'e2e-utils' | ||
| import { findPort } from 'next-test-utils' | ||
| import http from 'http' | ||
|
|
||
| describe('patch-fetch-request-body', () => { | ||
| let externalServerPort: number | ||
| let externalServer: http.Server | ||
|
|
||
| const { next, skipped } = nextTestSetup({ | ||
| files: __dirname, | ||
| skipStart: true, | ||
| skipDeployment: true, | ||
| }) | ||
|
|
||
| if (skipped) { | ||
| return | ||
| } | ||
|
|
||
| beforeAll(async () => { | ||
| externalServerPort = await findPort() | ||
|
|
||
| externalServer = http.createServer((req, res) => { | ||
| req.resume() | ||
| req.on('end', () => { | ||
| res.writeHead(401, { 'Content-Type': 'application/json' }) | ||
| res.end(JSON.stringify({ status: 401 })) | ||
| }) | ||
| }) | ||
|
|
||
| await new Promise<void>((resolve, reject) => { | ||
| externalServer.listen(externalServerPort, () => resolve()) | ||
| externalServer.once('error', reject) | ||
| }) | ||
|
|
||
| next.env.EXTERNAL_SERVER_PORT = String(externalServerPort) | ||
| await next.start() | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| externalServer?.close() | ||
| }) | ||
|
|
||
| // On Node 24.14+, patch-fetch previously reconstructed the Request using | ||
| // reqInput.url which lost the internal body source. undici then threw | ||
| // "TypeError: expected non-null body source" when sending the request. | ||
| it('should preserve Request body source for uncached POST requests', async () => { | ||
| const res = await next.fetch('/api/test-post', { method: 'POST' }) | ||
| expect(res.status).toBe(200) | ||
|
|
||
| const json = await res.json() | ||
| expect(json.status).toBe(401) | ||
| }) | ||
| }) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different than the original implementation. Can you add a comment explaining why this is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment explaining the branch.