Skip to content

Commit

Permalink
Change single fetch type override recommendation (#9336)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed May 1, 2024
1 parent 937d5b3 commit da96d35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Date: 2024-04-23

- Naked objects returned from `loader`/`action` functions are no longer automatically serialized to JSON responses
- Instead, they'll be streamed as-is via [`turbo-stream`](https://github.com/jacob-ebey/turbo-stream) which allows direct serialization of more complex types such as `Promise`, `Date`, `Map` instances, and more
- You will need to modify your `tsconfig.json`'s `include` array to infer types properly when using Single Fetch
- You will need to modify your `tsconfig.json`'s `compilerOptions.types` array to infer types properly when using Single Fetch
- The `headers` export is no longer used when Single Fetch is enabled in favor of a new `response` stub passed to your `loader`/`action` functions
- The `json`/`defer`/`redirect` utilities are deprecated when using Single Fetch (but still work _mostly_ the same)
- Actions no longer automatically revalidate on `4xx`/`5xx` responses - you can return a `2xx` to opt-into revalidation or use `shouldRevalidate`
Expand Down
13 changes: 8 additions & 5 deletions docs/guides/single-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ Without Single Fetch, any plain Javascript object returned from a `loader` or `a

With Single Fetch, naked objects will be streamed directly, so the built-in type inference is no longer accurate once you have opted-into Single Fetch. For example, they would assume that a `Date` would be serialized to a string on the client 😕.

In order to ensure you get the proper types when using Single Fetch, we've included a set of type overrides that you can include in your `tsconfig.json` which aligns the types with the Single Fetch behavior:
In order to ensure you get the proper types when using Single Fetch, we've included a set of type overrides that you can include in your `tsconfig.json`'s `compilerOptions.types` array which aligns the types with the Single Fetch behavior:

```json
{
"include": [
// ...
"node_modules/@remix-run/react/future/single-fetch.d.ts"
]
"compilerOptions": {
//...
"types": [
// ...
"@remix-run/react/future/single-fetch.d.ts"
]
}
}
```

Expand Down

0 comments on commit da96d35

Please sign in to comment.