fetch-event-source
fetch-event-source copied to clipboard
fetchEventSource() repeats request indefinitely
trafficstars
I have SSE-endpoint http://localhost/sse-endpoint that returns next data:
data:{text: "He"}
id:0
data:{text: "ll"}
id:2
data:{text: "o,"}
id:4
data:{text: " u"}
id:6
data:{text: "se"}
id:8
data:{text: "r!"}
id:10
I use this client code to fetch data:
import { fetchEventSource } from "@microsoft/fetch-event-source";
console.log('Start');
fetchEventSource("http://localhost/sse-endpoint"), {
method: "POST",
onmessage(ev) {
console.log('Received data');
console.log(ev.data);
}
});
Expected output:
Start
Received data
{text: "He"}
Received data
{text: "ll"}
Received data
{text: "o,"}
Received data
{text: " u"}
Received data
{text: "se"}
Received data
[{text: "r!"}
Actual output:
Start
Received data
{text: "He"}
Received data
{text: "ll"}
Received data
{text: "o,"}
Received data
{text: " u"}
Received data
{text: "se"}
Received data
[{text: "r!"}
Received data
{text: "He"}
Received data
{text: "ll"}
Received data
{text: "o,"}
Received data
{text: " u"}
Received data
{text: "se"}
Received data
[{text: "r!"}
// Output continues infinitely
In devtools tab "Network" I can see that requests to /sse-endpoint continues indefinitely