nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: remix-run/remix
Pull request #6512 (2023-05-31 17:26:35)

fix(remix-node): fix `NodeRequest`'s `clone` function
Updated tests from https://github.com/remix-run/remix/pull/5566

@tomer-yechiel 

Closes: https://github.com/remix-run/remix/issues/5520

- [ ] Docs
- [x] Tests

Testing Strategy:

Ensure instanceof passes as well as updating test to utilize a ReadableStream to ensure body is not being locked for clone / og consumers.



Patch:
diff --git a/.changeset/req-clone-instanceof.md b/.changeset/req-clone-instanceof.md
new file mode 100644
index 000000000..a83a3f1e2
--- /dev/null
+++ b/.changeset/req-clone-instanceof.md
@@ -0,0 +1,6 @@
+---
+"remix": patch
+"@remix-run/node": patch
+---
+
+Fix `request.clone() instanceof Request` returning false.
diff --git a/contributors.yml b/contributors.yml
index efe470f9d..dcac6473e 100644
--- a/contributors.yml
+++ b/contributors.yml
@@ -491,6 +491,7 @@
 - tombiju
 - tombyrer
 - TomerAberbach
+- tomer-yechiel
 - toyozaki
 - turkerdev
 - tvanantwerp
diff --git a/packages/remix-node/fetch.ts b/packages/remix-node/fetch.ts
index ce42c4ed8..f586469dd 100644
--- a/packages/remix-node/fetch.ts
+++ b/packages/remix-node/fetch.ts
@@ -41,7 +41,7 @@ class NodeRequest extends WebRequest {
   }
 
   public clone(): NodeRequest {
-    return super.clone() as NodeRequest;
+    return new NodeRequest(this);
   }
 }
 


Test patch:
diff --git a/packages/remix-node/__tests__/fetch-test.ts b/packages/remix-node/__tests__/fetch-test.ts
index 9468160d6..4fd79135e 100644
--- a/packages/remix-node/__tests__/fetch-test.ts
+++ b/packages/remix-node/__tests__/fetch-test.ts
@@ -1,4 +1,5 @@
 import { PassThrough } from "stream";
+import { ReadableStream } from "@remix-run/web-stream";
 
 import { Request } from "../fetch";
 
@@ -70,9 +71,15 @@ let test = {
 
 describe("Request", () => {
   it("clones", async () => {
-    let body = new PassThrough();
-    test.source.forEach((chunk) => body.write(chunk));
-    body.end();
+    let encoder = new TextEncoder();
+    let body = new ReadableStream({
+      start(controller) {
+        test.source.forEach((chunk) => {
+          controller.enqueue(encoder.encode(chunk));
+        });
+        controller.close();
+      },
+    });
 
     let req = new Request("http://test.com", {
       method: "post",
@@ -103,6 +110,8 @@ describe("Request", () => {
     file = clonedFormData.get("upload_file_1") as File;
     expect(file.name).toBe("1k_b.dat");
     expect(file.size).toBe(1023);
+
+    expect(cloned instanceof Request).toBeTruthy();
   });
 });