We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem
Reading a resource (e.g. by res.read(), res.value(), or res.state()) breaks reactivity on the component that performed the read.
res.read()
res.value()
res.state()
Steps To Reproduce
#[component] fn App() -> Element { let mut x = use_signal(|| 0); let res = use_resource(move || { println!("resource triggered {}", x()); async move { 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" } } }
Un-comment any of the uses of res to enable the bug.
res
Expected behavior
When res is not used, the console output with N button clicks will be:
resource triggered 0 effect triggered 0 resource triggered 1 effect triggered 1 ... resource triggered N effect triggered N
When all uses of res are un-commented, it is instead:
resource triggered 0 resource state Pending resource value None resource read None resource state Ready resource value Some(0) resource read Some(0)
where clicking the button has no effect.
The use_effect on the signal x still breaks even if res does not use x.
use_effect
x
Environment:
The text was updated successfully, but these errors were encountered:
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" } } }
Sorry, something went wrong.
jkelleyrtp
Successfully merging a pull request may close this issue.
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:
The text was updated successfully, but these errors were encountered: