Skip to content

Commit 4163101

Browse files
authored
feat(standard-server): support React Native by explicitly checking body (#445)
By explicitly check for `null` to indicate an intentionally empty body instead of relying on a truthy body check. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added documentation for integrating oRPC with React Native, including usage examples and notes on supported features. - Updated the sidebar to include React Native in the list of integrations. - **Bug Fixes** - Improved handling of empty request bodies to better support native environments like React Native. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 7336c81 commit 4163101

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

apps/content/.vitepress/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default defineConfig({
101101
{ text: 'SvelteKit', link: '/docs/integrations/svelte-kit' },
102102
{ text: 'Remix', link: '/docs/integrations/remix' },
103103
{ text: 'SolidStart', link: '/docs/integrations/solid-start' },
104+
{ text: 'React Native', link: '/docs/integrations/react-native' },
104105
],
105106
},
106107
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: React Native Integration
3+
description: Seamlessly integrate oRPC with React Native
4+
---
5+
6+
# React Native Integration
7+
8+
[React Native](https://reactnative.dev/) is a framework for building native apps using React.
9+
10+
## Fetch Link
11+
12+
React Native includes a [Fetch API](https://reactnative.dev/docs/network), so you can use oRPC out of the box.
13+
14+
::: warning
15+
However, the Fetch API in React Native has limitations. oRPC features like `File`, `Blob`, and `AsyncIteratorObject` aren't supported. Follow [Support Stream #27741](https://github.com/facebook/react-native/issues/27741) for updates.
16+
:::
17+
18+
```ts
19+
import { RPCLink } from '@orpc/client/fetch'
20+
21+
const link = new RPCLink({
22+
url: 'http://localhost:3000/rpc',
23+
headers: async ({ context }) => ({
24+
'x-api-key': context?.something ?? ''
25+
})
26+
// fetch: <-- polyfill fetch if needed
27+
})
28+
```
29+
30+
::: info
31+
The `link` can be any supported oRPC link, such as [RPCLink](/docs/client/rpc-link), [OpenAPILink](/docs/openapi/client/openapi-link), or another custom link.
32+
:::

packages/standard-server-fetch/src/body.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { generateContentDisposition, getFilenameFromContentDisposition } from '@
55
import { toEventIterator, toEventStream } from './event-iterator'
66

77
export async function toStandardBody(re: Request | Response): Promise<StandardBody> {
8-
if (!re.body) {
8+
/**
9+
* In native environments like React Native, the body may be `undefined` due to lack of streaming support.
10+
* Therefore, we explicitly check for `null` to indicate an intentionally empty body.
11+
*/
12+
if (re.body === null) {
913
return undefined
1014
}
1115

0 commit comments

Comments
 (0)