Skip to content

Commit

Permalink
Support 304 responses on document requests
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Sep 6, 2024
1 parent 1a97d25 commit a921909
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-socks-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/server-runtime": patch
---

Support 304 responses on document requests
25 changes: 20 additions & 5 deletions integration/single-fetch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,8 +1925,23 @@ test.describe("single-fetch", () => {
`,
},
});
let res = await fixture.requestSingleFetchData("/_root.data");
expect(res.data).toEqual({

// Document requests
let documentRes = await fixture.requestDocument("/");
let html = await documentRes.text();
expect(html).toContain("<body>");
expect(html).toContain("<h1>Hello from the loader!</h1>");
documentRes = await fixture.requestDocument("/", {
headers: {
"If-None-Match": "1234",
},
});
expect(documentRes.status).toBe(304);
expect(await documentRes.text()).toBe("");

// Data requests
let dataRes = await fixture.requestSingleFetchData("/_root.data");
expect(dataRes.data).toEqual({
root: {
data: {
message: "ROOT",
Expand All @@ -1938,13 +1953,13 @@ test.describe("single-fetch", () => {
},
},
});
res = await fixture.requestSingleFetchData("/_root.data", {
dataRes = await fixture.requestSingleFetchData("/_root.data", {
headers: {
"If-None-Match": "1234",
},
});
expect(res.status).toBe(304);
expect(res.data).toBeNull();
expect(dataRes.status).toBe(304);
expect(dataRes.data).toBeNull();
});

test.describe("revalidations/_routes param", () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ async function handleDocumentRequest(

let headers = getDocumentHeaders(build, context);

// 304 responses should not have a body or a content-type
if (context.statusCode === 304) {
return new Response(null, { status: 304, headers });
}

// Sanitize errors outside of development environments
if (context.errors) {
Object.values(context.errors).forEach((err) => {
Expand Down

0 comments on commit a921909

Please sign in to comment.