Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 304 responses on document requests #9955

Merged
merged 1 commit into from
Sep 6, 2024
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/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