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
InertElement is a static HTML element that renders its tags and attributes as raw, pre-rendered strings without owning typed attribute keys. Because it discards attribute metadata, the framework cannot implement add_any_attr for it, so calling that method panics. The message hints that this element type is only valid nested inside another view, never as a top-level return that would need attributes attached later.
Source
Thrown at tachys/src/html/mod.rs:170
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
- Convert the static markup into a typed element (e.g. the corresponding html::element from tachys/leptos) so attributes can be added.
- Wrap the InertElement in a parent element and keep it strictly as a child, adding attributes to the parent instead.
- If you need raw HTML plus attributes, render the raw string as the inner content of a typed element rather than using InertElement at the top level.
Example fix
// before
InertElement::new("<span>hi</span>").add_any_attr(class("bold"))
// after
let el = html::span().attr(class("bold")).child("hi"); Defensive patterns
Strategy: validation
Validate before calling
fn supports_attrs<V: RenderHtml>(v: &V) -> bool { !matches!(v as &dyn std::any::Any, _ if std::any::TypeId::of::<V>() == std::any::TypeId::of::<tachys::html::InertElement>()) } Type guard
fn is_inert<V: 'static>(_v: &V) -> bool { std::any::TypeId::of::<V>() == std::any::TypeId::of::<tachys::html::InertElement>() } Prevention
- Never return InertElement as a view root; always nest it inside a typed element.
- Prefer typed html:: elements whenever you need to attach attributes.
- Keep raw-HTML helpers isolated in a module that only renders children.
When it happens
Trigger: Calling .add_any_attr(...) on an InertElement, or returning an InertElement from a component/view at the top level where the framework tries to attach attributes to it.
Common situations: Wrapping hand-written static HTML strings (e.g. via the inert/raw element path) and then trying to add dynamic attributes like class or event directives; using an inert element as a component's root view and adding attributes at the call site.
Related errors
- InertElement does not support adding attributes. It should o
- rendering B to HTML without filling it
- rendering A to HTML without filling it
- Failed to find the route {path} requested by the user. This
- Static routes are not currently supported on WASM32 server t
AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01).
Data as JSON: /api/errors/e6829ceb78379b44.
Report an issue: GitHub.