Skip to content

Commit a0d4e9b

Browse files
authored
Remove response stub from LoaderFunctionArgs/ActionFunctionArgs (#9398)
1 parent 45c7552 commit a0d4e9b

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

.changeset/fresh-pigs-leave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@remix-run/server-runtime": patch
3+
---
4+
5+
Remove `response` stub from `LoaderFunctionArgs`/`ActionFunctionArgs`
6+
- Instead, you will need to use `defineLaoder`/`defineAction` with single fetch to gain type access to the `response` stub

packages/remix-server-runtime/data.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type {
1010
ActionFunctionArgs,
1111
LoaderFunction,
1212
LoaderFunctionArgs,
13-
ResponseStub,
1413
} from "./routeModules";
14+
import type { ResponseStub } from "./single-fetch";
1515

1616
/**
1717
* An object of unknown type for route loaders and actions provided by the
@@ -49,7 +49,9 @@ export async function callRouteAction({
4949
request: stripDataParam(stripIndexParam(request)),
5050
context: loadContext,
5151
params,
52-
response,
52+
// Only provided when single fetch is enabled, and made available via
53+
// `defineAction` types, not `ActionFunctionArgs`
54+
...(singleFetch ? { response } : null),
5355
});
5456

5557
if (result === undefined) {
@@ -88,7 +90,9 @@ export async function callRouteLoader({
8890
request: stripDataParam(stripIndexParam(request)),
8991
context: loadContext,
9092
params,
91-
response,
93+
// Only provided when single fetch is enabled, and made available via
94+
// `defineLoader` types, not `LoaderFunctionArgs`
95+
...(singleFetch ? { response } : null),
9296
});
9397

9498
if (result === undefined) {

packages/remix-server-runtime/routeModules.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@ export type DataFunctionArgs = RRActionFunctionArgs<AppLoadContext> &
2727
context: AppLoadContext;
2828
};
2929

30-
export const ResponseStubOperationsSymbol = Symbol("ResponseStubOperations");
31-
export type ResponseStubOperation = [
32-
"set" | "append" | "delete",
33-
string,
34-
string?
35-
];
36-
/**
37-
* A stubbed response to let you set the status/headers of your response from
38-
* loader/action functions
39-
*/
40-
export type ResponseStub = {
41-
status: number | undefined;
42-
headers: Headers;
43-
};
44-
45-
export type ResponseStubImpl = ResponseStub & {
46-
[ResponseStubOperationsSymbol]: ResponseStubOperation[];
47-
};
48-
4930
/**
5031
* A function that handles data mutations for a route on the server
5132
*/
@@ -59,8 +40,6 @@ export type ActionFunction = (
5940
export type ActionFunctionArgs = RRActionFunctionArgs<AppLoadContext> & {
6041
// Context is always provided in Remix, and typed for module augmentation support.
6142
context: AppLoadContext;
62-
// TODO: (v7) Make this non-optional once single-fetch is the default
63-
response?: ResponseStub;
6443
};
6544

6645
/**
@@ -92,8 +71,6 @@ export type LoaderFunction = (
9271
export type LoaderFunctionArgs = RRLoaderFunctionArgs<AppLoadContext> & {
9372
// Context is always provided in Remix, and typed for module augmentation support.
9473
context: AppLoadContext;
95-
// TODO: (v7) Make this non-optional once single-fetch is the default
96-
response?: ResponseStub;
9774
};
9875

9976
/**

packages/remix-server-runtime/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ import {
4545
singleFetchAction,
4646
singleFetchLoaders,
4747
SingleFetchRedirectSymbol,
48+
ResponseStubOperationsSymbol,
4849
} from "./single-fetch";
4950
import { resourceRouteJsonWarning } from "./deprecations";
50-
import { ResponseStubOperationsSymbol } from "./routeModules";
5151

5252
export type RequestHandler = (
5353
request: Request,

packages/remix-server-runtime/single-fetch.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ import { encode } from "turbo-stream";
1515
import type { AppLoadContext } from "./data";
1616
import { sanitizeError, sanitizeErrors } from "./errors";
1717
import { ServerMode } from "./mode";
18-
import type {
19-
ResponseStub,
20-
ResponseStubImpl,
21-
ResponseStubOperation,
22-
} from "./routeModules";
23-
import { ResponseStubOperationsSymbol } from "./routeModules";
2418
import type { TypedDeferredData, TypedResponse } from "./responses";
2519
import { isDeferredData, isRedirectStatusCode, isResponse } from "./responses";
2620
import type { SerializeFrom } from "./serialize";
@@ -544,6 +538,26 @@ export type Serialize<T extends Loader | ClientLoader | Action | ClientAction> =
544538
Awaited<ReturnType<T>> extends TypedResponse<Record<string, unknown>> ? SerializeFrom<T> :
545539
Awaited<ReturnType<T>>;
546540

541+
export const ResponseStubOperationsSymbol = Symbol("ResponseStubOperations");
542+
export type ResponseStubOperation = [
543+
"set" | "append" | "delete",
544+
string,
545+
string?
546+
];
547+
548+
/**
549+
* A stubbed response to let you set the status/headers of your response from
550+
* loader/action functions
551+
*/
552+
export type ResponseStub = {
553+
status: number | undefined;
554+
headers: Headers;
555+
};
556+
557+
export type ResponseStubImpl = ResponseStub & {
558+
[ResponseStubOperationsSymbol]: ResponseStubOperation[];
559+
};
560+
547561
// loader
548562
type LoaderArgs = RRLoaderArgs<AppLoadContext> & {
549563
// Context is always provided in Remix, and typed for module augmentation support.

0 commit comments

Comments
 (0)