DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
20.05k stars 764 forks source link

Inline rsx within match never reevaluated when on of the arm's returns an empty rsx. #2020

Closed lostb1t closed 5 months ago

lostb1t commented 5 months ago

Inline rsx within match never reevaluated when on of the arm's renders an empty rsx.

In the example hello world is never re-rendered after toggling.


use dioxus::prelude::*;

fn main() {
    launch(app);
}

fn app() -> Element {
    let mut running = use_signal(|| true);

    rsx! {
        div {
            button { onclick: move |_| running.toggle(), "Toggle" }
            match running() {
                true => {
                    rsx! {
                        "Hello world"
                    }
                }
                // works
                // false => rsx!{div {}}
                // does not work, hello world never rerenders.
                false => rsx!{}
            }
        }
    }
}
ealmloff commented 5 months ago

rsx!{} expands to a template with no nodes. Because it has no root nodes, dioxus doesn't know what to replace with "Hello world". Instead of rendering no nodes, we should treat rsx!{} like rsx!{{}} which renders a placeholder

jkelleyrtp commented 5 months ago

Fixed by #2020