Link to the code that reproduces this issue
https://github.com/dkokotov/nextjs-edge-request-cloning-bug
To Reproduce
- Start the application in development
- Navigate to http://localhost:3000
- Observe that the method and headers of request 2 do not match those of request 1, even though request 2 was created by cloning request 1 (
const req2 = new Request(req1))
Current vs. Expected behavior
Request 2 method and body should be the same as those of request 1.
Note this only happens for edge runtime. If, in the example below copied from the repro repository), I comment out the export const runtime = 'edge', the output is as expected.
export default function Home() {
const req1 = new Request('https://example.com', {
method: 'POST',
headers: { 'X-Example-Header': 'Foo' }
});
const req2 = new Request(req1);
return <div>
Request 1 method: {req1.method}
<br/>
Request 1 headers: {req1.headers}
<br/>
Request 2 method: {req2.method}
<br/>
Request 2 headers: {req2.headers}
</div>
}
export const runtime = 'edge';
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
Node: 20.8.0
npm: 10.1.0
Yarn: 1.22.19
pnpm: 8.7.5
Relevant Packages:
next: 14.0.2-canary.5
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Middleware / Edge (API routes, runtime)
Additional context
Seems to only happen for running in dev mode. If I deploy the repro example to Vercel (https://nextjs-edge-request-cloning-bug.vercel.app), the output is as expected.
Link to the code that reproduces this issue
https://github.com/dkokotov/nextjs-edge-request-cloning-bug
To Reproduce
const req2 = new Request(req1))Current vs. Expected behavior
Request 2 method and body should be the same as those of request 1.
Note this only happens for edge runtime. If, in the example below copied from the repro repository), I comment out the
export const runtime = 'edge', the output is as expected.Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 Binaries: Node: 20.8.0 npm: 10.1.0 Yarn: 1.22.19 pnpm: 8.7.5 Relevant Packages: next: 14.0.2-canary.5 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/AWhich area(s) are affected? (Select all that apply)
App Router, Middleware / Edge (API routes, runtime)
Additional context
Seems to only happen for running in dev mode. If I deploy the repro example to Vercel (https://nextjs-edge-request-cloning-bug.vercel.app), the output is as expected.