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

Remove streaming FAQ re: React Native #244

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
41 changes: 0 additions & 41 deletions docs/web/supported-browsers-and-frameworks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,3 @@ integrates seamlessly with various module loaders and bundlers such as [esbuild]
[Vite](https://vitejs.dev) and [Rollup](https://rollupjs.org).

You can find examples for many popular frameworks in the [examples-es](https://github.com/connectrpc/examples-es) repo.

## React Native

[React Native](https://reactnative.dev) does not offer great support for the Fetch API and the Text Encoding API. As
such, React Native requires a polyfill for these two implementations. We recommend the following to accomplish this:

1. Install the polyfills.

```bash
npm install react-native-fast-encoder react-native-fetch-api web-streams-polyfill
```

2. Apply the polyfills in the root of your app.

```js
import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions"
import TextEncoder from "react-native-fast-encoder"
import { fetch, Headers, Request, Response } from "react-native-fetch-api"
import { ReadableStream } from "web-streams-polyfill"

polyfillGlobal("ReadableStream", () => ReadableStream)
polyfillGlobal("TextDecoder", () => TextEncoder)
polyfillGlobal("TextEncoder", () => TextEncoder)
polyfillGlobal(
"fetch", () => (...args) => fetch(args[0], {
...args[1],
// Inject textStreaming: https://github.com/react-native-community/fetch/issues/15
reactNative: { textStreaming: true }
}),
)
polyfillGlobal("Headers", () => Headers)
polyfillGlobal("Request", () => Request)
polyfillGlobal("Response", () => Response)
```

Unfortunately, only unary requests via the [Connect protocol](../protocol.md) are supported in
React Native due to some limitations in React Native's implementation of the Fetch API. For more information, please see
[this issue](https://github.com/connectrpc/connect-es/issues/199)

For a working example, see the [React Native project](https://github.com/connectrpc/examples-es/tree/main/react-native)
in the [examples-es](https://github.com/connectrpc/examples-es) repo.