Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-dodos-shop.md
Original file line number Diff line number Diff line change
@@ -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
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 @@ -10952,8 +10958,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
Original file line number Diff line number Diff line change
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,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment we are not persisting method:'POST' as Remix did since we think that should be changed in Remix

let context = await loadRouteData(loaderRequest, matches, requestContext);

return {
Expand Down