DioxusLabs/dioxus · error

not a valid node

Error message

not a valid node

What it means

After downcasting the event target to a Node, `walk_event_for_id` `expect`s the cast to succeed. This panic fires when an event target is not a DOM Node — indicating an unexpected event type reaching the web renderer's event-to-ElementId resolution, an internal invariant violation.

Source

Thrown at packages/web/src/dom.rs:129

            interpreter,
            #[cfg(feature = "mounted")]
            runtime,
            #[cfg(feature = "mounted")]
            queued_mounted_events: Default::default(),
            #[cfg(feature = "mounted")]
            current_writing_id: ElementId::from_raw(0),
            #[cfg(feature = "hydrate")]
            suspense_hydration_ids: Default::default(),
        }
    }
}

fn walk_event_for_id(event: &web_sys::Event) -> Option<(ElementId, web_sys::Element)> {
    let target = event
        .target()
        .expect("missing target")
        .dyn_into::<web_sys::Node>()
        .expect("not a valid node");

    walk_element_for_id(&target)
}

fn walk_element_for_id(target: &Node) -> Option<(ElementId, web_sys::Element)> {
    let mut current_target_element = target.dyn_ref::<web_sys::Element>().cloned();

    loop {
        match (
            current_target_element
                .as_ref()
                .and_then(|el| el.get_attribute("data-dioxus-id").map(|f| f.parse())),
            current_target_element,
        ) {
            // This node is an element, and has a dioxus id, so we can stop walking
            (Some(Ok(id)), Some(target)) => return Some((ElementId::from_raw(id), target)),

            // Walk the tree upwards until we actually find an event target

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Ensure the value being mounted or queried is a valid DOM Node; do not pass detached or wrong-typed JS values to the DOM API.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at packages/web/src/dom.rs:129 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/c839cbbc20bc187a. Report an issue: GitHub.