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

RELEASE: fix json and defer when using single fetch types #9944

Merged
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
2 changes: 1 addition & 1 deletion .changeset/moody-cups-give.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Single Fetch: Improved typesafety

If you were already using single-fetch types:
If you were already using previously released unstable single-fetch types:

- Remove `"@remix-run/react/future/single-fetch.d.ts"` override from `tsconfig.json` > `compilerOptions` > `types`
- Remove `defineLoader`, `defineAction`, `defineClientLoader`, `defineClientAction` helpers from your route modules
Expand Down
5 changes: 5 additions & 0 deletions .changeset/neat-mayflies-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"remix": patch
---

REMOVE: bump prerelease version
13 changes: 10 additions & 3 deletions packages/remix-server-runtime/single-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { AppLoadContext } from "./data";
import { sanitizeError, sanitizeErrors } from "./errors";
import { getDocumentHeaders } from "./headers";
import { ServerMode } from "./mode";
import type { TypedResponse } from "./responses";
import type { TypedDeferredData, TypedResponse } from "./responses";
import { isRedirectStatusCode, isResponse } from "./responses";
import type { Jsonify } from "./jsonify";
import type {
Expand Down Expand Up @@ -427,10 +427,12 @@ type Fn = (...args: any[]) => unknown;
// prettier-ignore
export type SerializeFrom<T extends Fn> =
Parameters<T> extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ?
ReturnType<T> extends TypedResponse<infer U> ? Jsonify<U> :
Awaited<ReturnType<T>> extends TypedResponse<infer U> ? Jsonify<U> :
Awaited<ReturnType<T>> extends TypedDeferredData<infer U> ? U :
Awaited<ReturnType<T>>
:
Awaited<ReturnType<T>> extends TypedResponse<Record<string, unknown>> ? Jsonify<T> :
Awaited<ReturnType<T>> extends TypedResponse<infer U> ? Jsonify<U> :
Awaited<ReturnType<T>> extends TypedDeferredData<infer U> ? Serialize<U> :
Awaited<ReturnType<T>> extends DataWithResponseInit<infer D> ? Serialize<D> :
Serialize<Awaited<ReturnType<T>>>;

Expand Down Expand Up @@ -470,6 +472,8 @@ type Recursive = {
recursive?: Recursive;
};

type Pretty<T> = { [K in keyof T]: T[K] } & {};

// prettier-ignore
// eslint-disable-next-line
type _tests = [
Expand Down Expand Up @@ -597,4 +601,7 @@ type _tests = [
function: () => void,
class: TestClass
}>>,

Expect<Equal<Pretty<SerializeFrom<ServerLoader<TypedResponse<{a: string, b: Date}>>>>, { a: string, b: string }>>,
Expect<Equal<Pretty<SerializeFrom<ServerLoader<TypedDeferredData<{a: string, b: Promise<Date>}>>>>, { a: string, b: Promise<Date> }>>,
]