DioxusLabs/dioxus · error

event listener should be added successfully

Error message

event listener should be added successfully

What it means

The devtools playground registers a window `message` event listener and `expect`s `add_event_listener_with_callback` to succeed. This panic fires if the browser refuses to attach the listener (rare; e.g. invalid closure or unsupported context), breaking hot-reload message receiving in the playground iframe.

Source

Thrown at packages/web/src/devtools.rs:305

/// This listens for window message events from other Windows (such as window.top when this is running in an iframe).
fn playground(tx: UnboundedSender<HotReloadMsg>) {
    let window = web_sys::window().expect("this code should be running in a web context");

    let binding = Closure::<dyn FnMut(MessageEvent)>::new(move |e: MessageEvent| {
        let Ok(text) = e.data().dyn_into::<JsString>() else {
            return;
        };
        let string: String = text.into();
        let Ok(hr_msg) = serde_json::from_str::<HotReloadMsg>(&string) else {
            return;
        };
        _ = tx.unbounded_send(hr_msg);
    });

    let callback = binding.as_ref().unchecked_ref();
    window
        .add_event_listener_with_callback("message", callback)
        .expect("event listener should be added successfully");

    binding.forget();
}

fn hook_impl(info: &std::panic::PanicHookInfo) {
    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(js_namespace = console)]
        fn error(msg: String);

        type Error;

        #[wasm_bindgen(constructor)]
        fn new() -> Error;

        #[wasm_bindgen(structural, method, getter)]
        fn stack(error: &Error) -> String;
    }

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Ensure the event target exists and supports the event listener being registered; check the browser console for the underlying DOM exception.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/web/src/devtools.rs:305 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/5d0a80fede260e57. Report an issue: GitHub.