Same code is retuning in chunks in node js. I have done polyfillFetch in react native to support streaming. But it’s not sending in chunks, it’s sending the complete text after some time. I am using expo for the app
import {
polyfill,
polyfill as polyfillFetch,
} from "react-native-polyfill-globals/src/fetch";
import "react-native-get-random-values";
import "react-native-url-polyfill/auto";
import { ReadableStream } from "web-streams-polyfill";
import "text-encoding-polyfill";
globalThis.ReadableStream = ReadableStream;
polyfill();
const fetchData = async () => {
console.log("fetch");
const response = fetch(
"https://sample.lambda-url.us-east-1.on.aws/",
{
reactNative: { textStreaming: true },
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: "how are you ?",
}),
}
).then((response) => response.body)
.then( async (body) => {
const reader = body.getReader()
const decoder = new TextDecoder("utf-8");
while (true) {
const { value, done } = await reader.read()
if (done) {
break
}
const decodedChunk = decoder.decode(value, { stream: true })
console.log(decodedChunk);
}
});
};