diff --git a/.changeset/req-clone-instanceof.md b/.changeset/req-clone-instanceof.md new file mode 100644 index 00000000000..a83a3f1e233 --- /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 efe470f9df8..dcac6473ed5 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/__tests__/fetch-test.ts b/packages/remix-node/__tests__/fetch-test.ts index 9468160d65a..4fd79135ee5 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(); }); }); diff --git a/packages/remix-node/fetch.ts b/packages/remix-node/fetch.ts index ce42c4ed8d3..f586469dd35 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); } }