Skip to content

Commit

Permalink
Fix loader request on document POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Dec 12, 2022
1 parent 108e5c2 commit 09ef995
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10935,7 +10935,13 @@ describe("a router", () => {
],
},
]);
await query(createSubmitRequest("/child"));
await query(
createSubmitRequest("/child", {
headers: {
test: "value",
},
})
);

// @ts-expect-error
let actionRequest = actionStub.mock.calls[0][0]?.request;
Expand All @@ -10950,10 +10956,12 @@ describe("a router", () => {
let rootLoaderRequest = rootLoaderStub.mock.calls[0][0]?.request;
// @ts-expect-error
let childLoaderRequest = childLoaderStub.mock.calls[0][0]?.request;
expect(rootLoaderRequest.method).toBe("GET");
expect(rootLoaderRequest.method).toBe("POST");
expect(rootLoaderRequest.url).toBe("http://localhost/child");
expect(childLoaderRequest.method).toBe("GET");
expect(rootLoaderRequest.headers.get("test")).toBe("value");
expect(childLoaderRequest.method).toBe("POST");
expect(childLoaderRequest.url).toBe("http://localhost/child");
expect(childLoaderRequest.headers.get("test")).toBe("value");
});

it("should support a requestContext passed to loaders and actions", async () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2256,8 +2256,14 @@ export function unstable_createStaticHandler(
};
}

// Create a GET request for the loaders
let loaderRequest = new Request(request.url, { signal: request.signal });
// Create a request for the loaders
let loaderRequest = new Request(request.url, {
body: null,
headers: request.headers,
method: request.method,
redirect: request.redirect,
signal: request.signal,
});
let context = await loadRouteData(loaderRequest, matches, requestContext);

return {
Expand Down

0 comments on commit 09ef995

Please sign in to comment.