DioxusLabs/dioxus · error

SSE should be initialized before using it as a response

Error message

SSE should be initialized before using it as a response

What it means

`ServerEvents::into_response` requires the SSE stream to have been initialized (via `from_sse` or the client constructor); it `expect`s the inner Option to hold an Sse. This panic fires when an uninitialized `ServerEvents` (no stream and no client) is used directly as an axum response.

Source

Thrown at packages/fullstack/src/payloads/sse.rs:355

        /// Create a `ServerEvents` from an existing Axum `Sse` response.
        #[allow(clippy::type_complexity)]
        pub fn from_sse(
            sse: Sse<Pin<Box<dyn Stream<Item = Result<Event, BoxError>> + Send>>>,
        ) -> Self {
            Self {
                _marker: std::marker::PhantomData,
                client: None,
                keep_alive: None,
                sse: Some(sse),
            }
        }
    }

    impl<T> IntoResponse for ServerEvents<T> {
        fn into_response(self) -> axum_core::response::Response {
            let sse = self
                .sse
                .expect("SSE should be initialized before using it as a response");

            if let Some(keep_alive) = self.keep_alive {
                sse.keep_alive(keep_alive).into_response()
            } else {
                sse.into_response()
            }
        }
    }

    /// A transmitter for sending events to the SSE stream.
    pub struct SseTx<T> {
        sender: futures_channel::mpsc::UnboundedSender<axum::response::sse::Event>,
        _marker: std::marker::PhantomData<fn() -> T>,
    }

    impl<T: Serialize> SseTx<T> {
        /// Sends an event to the SSE stream.
        pub async fn send(&mut self, event: T) -> anyhow::Result<()> {

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Initialize the SSE stream (e.g. via the provided SSE constructor) before using it as a server function response.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at packages/fullstack/src/payloads/sse.rs:355 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/0a072d485d0f8f94. Report an issue: GitHub.