Skip to content
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

NextRequest constructor doesn't match Request behaviour for cloning #52967

Closed
1 task done
tom-sherman opened this issue Jul 20, 2023 · 2 comments · Fixed by #53157
Closed
1 task done

NextRequest constructor doesn't match Request behaviour for cloning #52967

tom-sherman opened this issue Jul 20, 2023 · 2 comments · Fixed by #53157
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@tom-sherman
Copy link

tom-sherman commented Jul 20, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.13.0
      npm: 8.13.2
      Yarn: 1.22.19
      pnpm: 8.6.6
    Relevant Packages:
      next: 13.4.11-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.4
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App Router, Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/tom-sherman/nextrequest-consructor-bug

To Reproduce

Attempt to clone the request like so:

const newRequest = new NextRequest(request)

Describe the Bug

Headers and body isn't preserved from request in route handlers and middleware.

Expected Behavior

As is with new Request(request), headers and body should be preserved/copied into the new request object.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1468

@tom-sherman tom-sherman added the bug Issue was opened via the bug report template. label Jul 20, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Jul 20, 2023
@tom-sherman
Copy link
Author

The workaround is to pass the original request in twice:

new NextRequest(request, request)

I suspect Next.js is only cloning the url from the first argument.

@balazsorban44 balazsorban44 added the linear: next Confirmed issue that is tracked by the Next.js team. label Jul 25, 2023
@kodiakhq kodiakhq bot closed this as completed in #53157 Jul 25, 2023
kodiakhq bot pushed a commit that referenced this issue Jul 25, 2023
### What?

Allow the following:

```ts
new NextRequest(new Request(...))
```

### Why?

Cloning a request by passing it to the constructor of another `Request` is allowed by the spec: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#parameters

### How?

If the passed argument is an instance of `Request`, we pass it as-is to `super()`

Fixes #52967
Closes NEXT-1468
rfearing pushed a commit to rfearing/next.js that referenced this issue Jul 26, 2023
### What?

Allow the following:

```ts
new NextRequest(new Request(...))
```

### Why?

Cloning a request by passing it to the constructor of another `Request` is allowed by the spec: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#parameters

### How?

If the passed argument is an instance of `Request`, we pass it as-is to `super()`

Fixes vercel#52967
Closes NEXT-1468
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants