sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

view! compile error when passing empty Children through component #588

Closed zdenek-crha closed 3 weeks ago

zdenek-crha commented 1 year ago

Describe the bug

When component prop struct contains only Children struct and view! macro is used to render it without child node(s), then compilation fails with an argument of type AppProps<'_, _> is missing.

To Reproduce

use sycamore::prelude::*;

#[derive(Prop)]
pub struct AppProps<'cx, G: Html> {
    children: Children<'cx, G>,
}

#[component]
pub fn App<'cx, G: Html>(cx: Scope<'cx>, props: AppProps<'cx, G>) -> View<G> {
    let children = props.children.call(cx);
    view! { cx, (children) }
}

pub fn main() {
    sycamore::render(|cx| view! { cx,
        App { }
    });
}

Expected behavior

Code compiles without issue and AppProps contains Children struct instance that has no child nodes.

Environment

Additional context

This seems to be an edge-case in view! macro building the AppProps struct from component attributes and children. It manifests only in the case described above. Any of the following changes will make it compile:

lukechu10 commented 3 weeks ago

This issue was actually solved way back with #548, I just didn't realize it 😅