leptos-rs/leptos · error

List of slots must not be empty

Error message

List of slots must not be empty

What it means

In the view! macro's component builder, when a component invocation contains slot parameters, the macro drains a map of slot names to token values and calls values.last().expect("List of slots must not be empty") to get a span. This panics if the slot map somehow contains a key with an empty values list, indicating an internal invariant violation while parsing slot assignments in the component call.

Source

Thrown at leptos_macro/src/view/component_builder.rs:265

                }
            } else {
                quote_spanned! {children.span()=>
                    .children({
                        #(#clonables)*

                        ::leptos::children::ToChildren::to_children(move || #children)
                    })
                }
            }
        } else {
            quote! {}
        }
    };

    let slots = slots.drain().map(|(slot, mut values)| {
        let span = values
            .last()
            .expect("List of slots must not be empty")
            .span();
        let slot = Ident::new(&slot, span);
        let value = if values.len() > 1 {
            quote_spanned! {span=>
                ::std::vec![
                    #(#values)*
                ]
            }
        } else {
            values.remove(0)
        };

        quote! { .#slot(#value) }
    });

    let generics = &node.open_tag.generics;
    let generics = if generics.lt_token.is_some() {
        quote! { ::#generics }

View on GitHub (pinned to 32d20f6c9d)

Solutions

  1. Write slots in the documented form: <Child slot:name>...</Child> inside the component, ensuring each slot has content/values
  2. Remove empty or malformed slot markup from the component invocation
  3. Align leptos and leptos_macro versions (update via cargo update -p leptos so the macro matches the runtime)
  4. Reduce the view! to a minimal case and report the parsing edge case upstream if the syntax looks valid

Example fix

// before (empty/malformed slot)
view! { <Card> <slot /> </Card> }
// after
view! { <Card> <CardHeader slot:name> <h1>"Title"</h1> </CardHeader> </Card> }
Defensive patterns

Strategy: validation

Validate before calling

// Static check in a test: every <Comp> invocation in view! uses documented slot syntax
// (grep CI check for '<slot' or empty slot children inside component calls)

Prevention

When it happens

Trigger: Using <Component> with a <Bind:{slot} children=...>-style slot syntax (or custom slot syntax) that produces an empty values vector, typically via unusual/empty slot markup or macro-version-specific parsing edge cases.

Common situations: Macro/version mismatches between leptos_macro and leptos; copy-pasted slot syntax from another framework (e.g. children props written oddly); empty slot blocks like <slot /> inside a component in a form the parser mishandles.

Related errors


AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01). Data as JSON: /api/errors/3d2f686e8ac55d7b. Report an issue: GitHub.