Skip to content

Commit

Permalink
Fix loader request on document POST requests (#9721)
Browse files Browse the repository at this point in the history
* Fix loader request on document POST requests

* add changeset

* assert empty body

* Keep GET method for loader requests

* update changeset
  • Loading branch information
brophdawg11 committed Dec 13, 2022
1 parent c194f4a commit e54fbab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-dodos-shop.md
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Persist `headers` on `loader` `request`'s after SSR document `action` request
12 changes: 11 additions & 1 deletion packages/router/__tests__/router-test.ts
Expand Up @@ -10990,7 +10990,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 @@ -11007,8 +11013,12 @@ describe("a router", () => {
let childLoaderRequest = childLoaderStub.mock.calls[0][0]?.request;
expect(rootLoaderRequest.method).toBe("GET");
expect(rootLoaderRequest.url).toBe("http://localhost/child");
expect(rootLoaderRequest.headers.get("test")).toBe("value");
expect(await rootLoaderRequest.text()).toBe("");
expect(childLoaderRequest.method).toBe("GET");
expect(childLoaderRequest.url).toBe("http://localhost/child");
expect(childLoaderRequest.headers.get("test")).toBe("value");
// Can't re-read body here since it's the same request as the root
});

it("should support a requestContext passed to loaders and actions", async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/router/router.ts
Expand Up @@ -2257,7 +2257,11 @@ export function unstable_createStaticHandler(
}

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

return {
Expand Down

0 comments on commit e54fbab

Please sign in to comment.