SSE not working with Rust Yew, different errors occuring

I recently tried to connect my Yew frontend app to an actix-web SSE server I use to send events to the page. I tried different approaches and crates like EventSource from “web_sys”, “sse_client” and “gloo_net” but none of them worked.
Sometimes I got CORS errors but now I only get a connection error by the Browser.
For a while the Browser console also said, my callback function got either dropped or was called recursively.

I know that my SSE server works at least in some way. With curl I can connect without problem and receive all events that are emitted. So the problem should be related to my frontend code.

I uploaded a working example with server and client to GitHub using gloo_net crate:
https://github.com/heureka-code/sse-test

This is the part of the frontend that matters:

#[function_component(App)]
pub fn app() -> Html {
    use wasm_bindgen_futures::spawn_local;
    let src = gloo_net::eventsource::futures::EventSource::new("localhost:9000/sse");
    use futures::StreamExt;

    log::info!("{src:?}"); // status: Connecting

    if let Ok(mut event_source) = src {
        let mut stream1 = event_source.subscribe("test-event").unwrap();

        spawn_local(async move {
            log::info!("{event_source:?}"); // status: Connecting
            log::info!("First: {:?}", stream1.next().await); // Some(Err(ConnectionError))
            log::info!("{event_source:?}"); // status: Closed
            while let Some(Ok((event_type, msg))) = stream1.next().await {
                log::warn!("New message: {event_type} {msg:?}");
            }
            log::info!("Finished");
        });
        log::info!("After spawn");
    }

    html!()
}

This is the SSE route of the server:

use actix_web::{get, Responder};
use actix_web_lab::sse;
use std::time::Duration;
use tokio::time::sleep;

#[get("/sse")]
async fn stream_updates() -> impl Responder {
    let (tx, rx) = tokio::sync::mpsc::channel(10);

    tokio::spawn(async move {
        for i in 0..10 {
            let _ = tx
                .send(sse::Data::new(i.to_string()).event("test-event").into())
                .await;
            sleep(tokio::time::Duration::from_secs(1)).await;
        }
    });

    let sse = sse::Sse::from_infallible_receiver(rx).with_retry_duration(Duration::from_secs(10));
    let sse = sse
        .customize()
        .append_header(("Access-Control-Allow-Origin", "*"))
        .append_header(("Access-Control-Allow-Headers", "content-type"));
    return sse;
}

I tried different libraries but never received helpful error messages.
You can start the server inside it’s directory as normal with cargo run.

The frontend code can be executed like explained here:
https://yew.rs/docs/getting-started/introduction

When running you can look at the browser’s console or with curl at
localhost:9000/sse

If my system is relevant for the problem, I’m using Linux and Firefox.

Maybe it’s a simple solution but I don’t know what to try next. Maybe someone could help?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật