Open elias098 opened 2 weeks ago
If this is intended it should probably be documented. this might also just be me being used to leptos and not understanding dioxus version properly.
Looks like signals mutated from async tasks do not rerun effects
Doesn't work:
fn app() -> Element {
let mut count = use_signal(|| 0);
use_effect(move || {
println!("{}", count());
});
use_hook(move || {
spawn(async move {
loop {
sleep(Duration::from_secs(1)).await;
count += 1
}
})
});
rsx!(
button {
onclick: move |_| println!("{}", count()),
"read"
}
button {
onclick: |_| needs_update(),
"rerun"
}
)
}
Works:
fn app() -> Element {
let mut count = use_signal(|| 0);
use_effect(move || {
println!("{}", count);
});
println!("rerunning");
rsx!(
button {
onclick: move |_| count += 1,
"Increase"
}
button {
onclick: |_| needs_update(),
"rerun"
}
)
}
Problem
Currently
use_effect
useswait_for_next_render().await;
which means that it only runs on renders.This is a problem if a signal gets updates without triggering a render.
One such instance is that a queue of updates build up, with one effect running on every render, as below.
Steps To Reproduce
Expected behavior
I would expect effects to run any time a used signal updates
Environment:
Questionnaire