DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.33k stars 736 forks source link

bug: Signals get subscribed on effect when only mutated #2197

Closed marc2332 closed 3 months ago

marc2332 commented 3 months ago

Problem

This goes into an infinite loop:

fn app() -> Element {
    let mut count = use_signal(|| 0);

    use_effect(move || {
        count.set(5);
        println!("{count}");
    });

    let x = count.read();

    rsx!(
        div {
            width: "100%",
            height: "100%",
            background: "blue",
            onclick: move |_| count += 1,
        }
    )
}

Expected behavior

Don't go into an infinite loop

Environment:

marc2332 commented 3 months ago

I literally realized I was reading the signal the moment I opened the issue