Skip to content

Commit d4c0d2c

Browse files
committed
Dedupe constants now that we're in one package
1 parent 5047f3f commit d4c0d2c

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ interface StreamTransferProps {
5656
nonce?: string;
5757
}
5858

59+
// some status codes are not permitted to have bodies, so we want to just
60+
// treat those as "no data" instead of throwing an exception.
61+
// 304 is not included here because the browser should fill those responses
62+
// with the cached body content.
63+
export const NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205]);
64+
5965
// StreamTransfer recursively renders down chunks of the `serverHandoffStream`
6066
// into the client-side `streamController`
6167
export function StreamTransfer({
@@ -543,11 +549,6 @@ async function fetchAndDecode(
543549
throw new ErrorResponseImpl(404, "Not Found", true);
544550
}
545551

546-
// some status codes are not permitted to have bodies, so we want to just
547-
// treat those as "no data" instead of throwing an exception.
548-
// 304 is not included here because the browser should fill those responses
549-
// with the cached body content.
550-
const NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205]);
551552
if (NO_BODY_STATUS_CODES.has(res.status)) {
552553
let routes: { [key: string]: SingleFetchResult } = {};
553554
if (routeId) {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ import type { ServerRoute } from "./routes";
2424
import { createStaticHandlerDataRoutes, createRoutes } from "./routes";
2525
import { createServerHandoffString } from "./serverHandoff";
2626
import { getDevServerHooks } from "./dev";
27-
import type { SingleFetchResult, SingleFetchResults } from "./single-fetch";
2827
import {
2928
encodeViaTurboStream,
3029
getSingleFetchRedirect,
3130
singleFetchAction,
3231
singleFetchLoaders,
33-
SingleFetchRedirectSymbol,
3432
SINGLE_FETCH_REDIRECT_STATUS,
35-
NO_BODY_STATUS_CODES,
3633
} from "./single-fetch";
3734
import { getDocumentHeaders } from "./headers";
3835
import type { EntryRoute } from "../dom/ssr/routes";
36+
import type {
37+
SingleFetchResult,
38+
SingleFetchResults,
39+
} from "../dom/ssr/single-fetch";
40+
import {
41+
NO_BODY_STATUS_CODES,
42+
SingleFetchRedirectSymbol,
43+
} from "../dom/ssr/single-fetch";
3944
import type { MiddlewareEnabled } from "../types/future";
4045

4146
export type RequestHandler = (

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,16 @@ import type {
1818
SingleFetchResult,
1919
SingleFetchResults,
2020
} from "../dom/ssr/single-fetch";
21-
import { SingleFetchRedirectSymbol } from "../dom/ssr/single-fetch";
21+
import {
22+
NO_BODY_STATUS_CODES,
23+
SingleFetchRedirectSymbol,
24+
} from "../dom/ssr/single-fetch";
2225
import type { AppLoadContext } from "./data";
2326
import { sanitizeError, sanitizeErrors } from "./errors";
2427
import { ServerMode } from "./mode";
2528
import { getDocumentHeaders } from "./headers";
2629
import type { ServerBuild } from "./build";
2730

28-
export type { SingleFetchResult, SingleFetchResults };
29-
export { SingleFetchRedirectSymbol };
30-
31-
// Do not include a response body if the status code is one of these,
32-
// otherwise `undici` will throw an error when constructing the Response:
33-
// https://github.com/nodejs/undici/blob/bd98a6303e45d5e0d44192a93731b1defdb415f3/lib/web/fetch/response.js#L522-L528
34-
//
35-
// Specs:
36-
// https://datatracker.ietf.org/doc/html/rfc9110#name-informational-1xx
37-
// https://datatracker.ietf.org/doc/html/rfc9110#name-204-no-content
38-
// https://datatracker.ietf.org/doc/html/rfc9110#name-205-reset-content
39-
// https://datatracker.ietf.org/doc/html/rfc9110#name-304-not-modified
40-
export const NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205, 304]);
41-
4231
// We can't use a 3xx status or else the `fetch()` would follow the redirect.
4332
// We need to communicate the redirect back as data so we can act on it in the
4433
// client side router. We use a 202 to avoid any automatic caching we might

0 commit comments

Comments
 (0)