Skip to content

Commit

Permalink
RELEASE: fix json and defer when using single fetch types (#9944)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori authored Sep 5, 2024
1 parent 97c18bf commit 53750b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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> }>>,
]

0 comments on commit 53750b7

Please sign in to comment.