Skip to content

Commit

Permalink
fix: change how request is "cloned" for loaders (remix-run#3218)
Browse files Browse the repository at this point in the history
* fix: change how request is "cloned" for loaders

* removed derrived properties from init
  • Loading branch information
jacob-ebey authored May 17, 2022
1 parent 50b41e1 commit 8bdd2f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/remix-server-runtime/__tests__/handler-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { json } from "../responses";
import { createRequestHandler } from "../server";

describe("createRequestHandler", () => {
it("retains request headers when stripping body off for loaders", async () => {
let handler = createRequestHandler({
routes: {
root: {
id: "routes/test",
path: "/test",
module: {
loader: ({ request }) => json(request.headers.get("X-Foo")),
} as any,
},
},
assets: {} as any,
entry: { module: {} as any },
});

let response = await handler(
new Request("http://.../test", {
headers: {
"X-Foo": "bar",
},
})
);

expect(await response.json()).toBe("bar");
});
});
5 changes: 4 additions & 1 deletion packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ async function handleDocumentRequest({
}

let loaderRequest = new Request(request.url, {
...request,
body: null,
headers: request.headers,
method: request.method,
redirect: request.redirect,
signal: request.signal,
});

let routeLoaderResults = await Promise.allSettled(
Expand Down

0 comments on commit 8bdd2f8

Please sign in to comment.