File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed
packages/react-router/lib Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff 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.
6266export const NO_BODY_STATUS_CODES = new Set ( [ 100 , 101 , 204 , 205 ] ) ;
6367
Original file line number Diff line number Diff 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" ;
3435import { getDocumentHeaders } from "./headers" ;
3536import type { EntryRoute } from "../dom/ssr/routes" ;
3637import 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" ;
4442import type { MiddlewareEnabled } from "../types/future" ;
4543
4644export 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
Original file line number Diff line number Diff line change @@ -35,6 +35,14 @@ import type { ServerBuild } from "./build";
3535// the user control cache behavior via Cache-Control
3636export 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+
3846export 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
You can’t perform that action at this time.
0 commit comments