From ff8239276b0b4304ce319805822ee49f8aa61355 Mon Sep 17 00:00:00 2001 From: Tomer Yechiel Date: Tue, 2 May 2023 17:45:16 +0300 Subject: [PATCH 1/3] fix request.clone() typing --- contributors.yml | 1 + packages/remix-node/__tests__/fetch-test.ts | 2 ++ packages/remix-node/fetch.ts | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/contributors.yml b/contributors.yml index ce4723b7560..f41e2ea1990 100644 --- a/contributors.yml +++ b/contributors.yml @@ -483,6 +483,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..6795d823fa5 100644 --- a/packages/remix-node/__tests__/fetch-test.ts +++ b/packages/remix-node/__tests__/fetch-test.ts @@ -103,6 +103,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); } } From 529680113175b82cc9beb3a09f844b48bb370f43 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Wed, 31 May 2023 10:23:29 -0700 Subject: [PATCH 2/3] chore: update test to operate on a ReadableStream to ensure cloning doesn't lock the stream for either stream consumer --- packages/remix-node/__tests__/fetch-test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/remix-node/__tests__/fetch-test.ts b/packages/remix-node/__tests__/fetch-test.ts index 6795d823fa5..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", @@ -104,7 +111,7 @@ describe("Request", () => { expect(file.name).toBe("1k_b.dat"); expect(file.size).toBe(1023); - expect(cloned instanceof Request).toBeTruthy() + expect(cloned instanceof Request).toBeTruthy(); }); }); From bd6f44289ee05d662013d6b383da03eda177b646 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Thu, 1 Jun 2023 13:09:32 -0700 Subject: [PATCH 3/3] changeset --- .changeset/req-clone-instanceof.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/req-clone-instanceof.md 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.