Skip to content

Commit 6a46e16

Browse files
committed
Fix 304 case
1 parent 48bc170 commit 6a46e16

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

packages/react-router/lib/dom/ssr/single-fetch.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ interface StreamTransferProps {
5555
nonce?: string;
5656
}
5757

58-
// some status codes are not permitted to have bodies, so we want to just
59-
// treat those as "no data" instead of throwing an exception.
60-
// 304 is not included here because the browser should fill those responses
58+
// Some status codes are not permitted to have bodies, so we want to just
59+
// treat those as "no data" instead of throwing an exception:
60+
// https://datatracker.ietf.org/doc/html/rfc9110#name-informational-1xx
61+
// https://datatracker.ietf.org/doc/html/rfc9110#name-204-no-content
62+
// https://datatracker.ietf.org/doc/html/rfc9110#name-205-reset-content
63+
//
64+
// Note: 304 is not included here because the browser should fill those responses
6165
// with the cached body content.
6266
export const NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205]);
6367

packages/react-router/lib/server-runtime/server.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ import {
3030
singleFetchAction,
3131
singleFetchLoaders,
3232
SINGLE_FETCH_REDIRECT_STATUS,
33+
SERVER_NO_BODY_STATUS_CODES,
3334
} from "./single-fetch";
3435
import { getDocumentHeaders } from "./headers";
3536
import type { EntryRoute } from "../dom/ssr/routes";
3637
import type {
3738
SingleFetchResult,
3839
SingleFetchResults,
3940
} from "../dom/ssr/single-fetch";
40-
import {
41-
NO_BODY_STATUS_CODES,
42-
SingleFetchRedirectSymbol,
43-
} from "../dom/ssr/single-fetch";
41+
import { SingleFetchRedirectSymbol } from "../dom/ssr/single-fetch";
4442
import type { MiddlewareEnabled } from "../types/future";
4543

4644
export type RequestHandler = (
@@ -453,7 +451,7 @@ async function handleDocumentRequest(
453451
let headers = getDocumentHeaders(build, context);
454452

455453
// Skip response body for unsupported status codes
456-
if (NO_BODY_STATUS_CODES.has(context.statusCode)) {
454+
if (SERVER_NO_BODY_STATUS_CODES.has(context.statusCode)) {
457455
return new Response(null, { status: context.statusCode, headers });
458456
}
459457

packages/react-router/lib/server-runtime/single-fetch.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ import type { ServerBuild } from "./build";
3535
// the user control cache behavior via Cache-Control
3636
export const SINGLE_FETCH_REDIRECT_STATUS = 202;
3737

38+
// Add 304 for server side - that is not included in the client side logic
39+
// because the browser should fill those responses with the cached data
40+
// https://datatracker.ietf.org/doc/html/rfc9110#name-304-not-modified
41+
export const SERVER_NO_BODY_STATUS_CODES = new Set([
42+
...NO_BODY_STATUS_CODES,
43+
304,
44+
]);
45+
3846
export async function singleFetchAction(
3947
build: ServerBuild,
4048
serverMode: ServerMode,
@@ -269,7 +277,7 @@ function generateSingleFetchResponse(
269277
resultHeaders.set("X-Remix-Response", "yes");
270278

271279
// Skip response body for unsupported status codes
272-
if (NO_BODY_STATUS_CODES.has(status)) {
280+
if (SERVER_NO_BODY_STATUS_CODES.has(status)) {
273281
return new Response(null, { status, headers: resultHeaders });
274282
}
275283

0 commit comments

Comments
 (0)