2035Builder
2035Builder6mo ago

TextDecoder not implemented Trpc react-native httpBatchStreamLink

Receiving the stream relies on the TextDecoder and TextDecoderStream APIs, which is not available in React Native. If you still want to enable streaming, you need to polyfill those. any refrence to this?
3 Replies
2035Builder
2035BuilderOP6mo ago
currently try
import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions"

const applyGlobalPolyfills = () => {
const { TextEncoder, TextDecoder } = require("text-encoding")

polyfillGlobal("TextEncoder", () => TextEncoder)
polyfillGlobal("TextDecoder", () => TextDecoder)
}

export default applyGlobalPolyfills
import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions"

const applyGlobalPolyfills = () => {
const { TextEncoder, TextDecoder } = require("text-encoding")

polyfillGlobal("TextEncoder", () => TextEncoder)
polyfillGlobal("TextDecoder", () => TextDecoder)
}

export default applyGlobalPolyfills
in my_layout.tsx
// calling this
applyGlobalPolyfills()
// calling this
applyGlobalPolyfills()
and ran expo run:ios but still getting same error
Gwendal
Gwendal3mo ago
Did you manage to manage to make it work eventually? I'm facing the same problem @2035Builder
Flip
Flip2w ago
I made a post on stackoverflow on how I got it to work https://stackoverflow.com/a/79428194/17990405
Stack Overflow
tRPC stream API response from OpenAI to React client
I am currently working on a way to implement the openai-node package into my Next.js application. Because of the long generation times of OpenAI completions, I want to make use of streaming (which is

Did you find this page helpful?