leptos-rs/leptos · error
InertElement does not support adding attributes. It should o
Error message
InertElement does not support adding attributes. It should only be used as a child, and not returned at the top level.
What it means
Identical to the HTML variant but for SVG: the SVG InertElement type stores pre-rendered markup as raw strings and cannot accept typed attributes, so add_any_attr panics. It is meant to be embedded as a child of another view only.
Source
Thrown at tachys/src/svg/mod.rs:259
el.insert_before_this(&mut new_el);
el.unmount();
*el = new_el;
*prev = self.html;
}
}
}
impl AddAnyAttr for InertElement {
type Output<SomeNewAttr: Attribute> = Self;
fn add_any_attr<NewAttr: Attribute>(
self,
_attr: NewAttr,
) -> Self::Output<NewAttr>
where
Self::Output<NewAttr>: RenderHtml,
{
panic!(
"InertElement does not support adding attributes. It should only \
be used as a child, and not returned at the top level."
)
}
}
impl RenderHtml for InertElement {
type AsyncOutput = Self;
type Owned = Self;
const MIN_LENGTH: usize = 0;
fn html_len(&self) -> usize {
self.html.len()
}
fn dry_resolve(&mut self) {}
View on GitHub (pinned to 32d20f6c9d)
Solutions
- Use tachys/leptos typed SVG elements (svg::path(), svg::circle(), etc.) so attributes are supported.
- Keep the inert SVG markup strictly as a child and add attributes to a typed wrapping element.
- Inline the needed attributes directly into the raw SVG string if it must remain inert.
Example fix
// before
InertElement::new("<path d='...'/>").add_any_attr(class("icon"))
// after
svg::path().attr(class("icon")).attr(d("M0 0 L10 10")) Defensive patterns
Strategy: type-guard
Validate before calling
fn svg_element_accepts_attrs<T: 'static>(_t: &T) -> bool { std::any::TypeId::of::<T>() != std::any::TypeId::of::<tachys::svg::InertElement>() } Type guard
fn is_svg_inert<T: 'static>(_v: &T) -> bool { std::any::TypeId::of::<T>() == std::any::TypeId::of::<tachys::svg::InertElement>() } Prevention
- Use typed svg:: elements when attributes are needed.
- Bake attributes directly into raw SVG strings.
- Never use inert SVG markup as a component root view.
When it happens
Trigger: Calling add_any_attr on an SVG InertElement, or returning it at the top level of a view/component where attribute attachment is attempted.
Common situations: Embedding raw SVG markup strings and then trying to attach class/id/event attributes; using raw SVG snippets as component roots.
Related errors
- InertElement does not support adding attributes. It should o
- Failed to find the route {path} requested by the user. This
- Static routes are not currently supported on WASM32 server t
- Reading from a LocalResource outside Suspense in `ssr` mode
- Unrecoverable hydration error. Please read the error message
AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01).
Data as JSON: /api/errors/fa4acb89857e3a66.
Report an issue: GitHub.