Closed thorn132 closed 2 months ago
It seems like the duration of the future matters here. This code works as expected:
fn app() -> Element {
let mut x = use_signal(|| 0);
let res = use_resource(move || {
println!("resource triggered {}", x());
async move {
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
x()
}
});
use_effect(move || println!("effect triggered {}", x()));
println!("resource state {:?}", res.state());
println!("resource value {:?}", res.value());
println!("resource read {:?}", res.read());
rsx! {
button {
onclick: move |_| x += 1,
"Trigger"
}
}
}
Problem
Reading a resource (e.g. by
res.read()
,res.value()
, orres.state()
) breaks reactivity on the component that performed the read.Steps To Reproduce
Un-comment any of the uses of
res
to enable the bug.Expected behavior
When
res
is not used, the console output with N button clicks will be:When all uses of
res
are un-commented, it is instead:where clicking the button has no effect.
The
use_effect
on the signalx
still breaks even ifres
does not usex
.Environment: