-
-
Notifications
You must be signed in to change notification settings - Fork 725
New issue
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
MountedData does not properly being updated after rerendering. #2420
Comments
I found something weird on the |
Note there is a difference between rerendering a component and rerendering an element. An element should only be recreated when you switch to a new rsx block. If you rerun the component, but return the same rsx block then the element should not be recreated and the onmounted event should not trigger again In the following code, toggle will recreate the element and trigger the event. It seems to work as I would expect. Can you identify anything different your code does differently that may be triggering the issue? #![allow(non_snake_case)]
use std::time::Duration;
use dioxus::prelude::*;
fn main() {
launch(app)
}
fn app() -> Element {
let mut count = use_signal(|| 0);
let mut toggle = use_signal(|| false);
use_future(move || async move {
loop {
tokio::time::sleep(Duration::from_millis(100)).await;
count += 1
}
});
if toggle() {
rsx! {
button {
onclick: move |_| toggle.toggle(),
"toggle"
}
div {
onmounted: move |evt| {
async move {
loop {
tokio::time::sleep(Duration::from_millis(100)).await;
println!("{:?}", evt.get_client_rect().await);
}
}
},
width: "{count}px",
height: "{count}px",
style: "background-color: red",
}
}
}
else {
rsx! {
button {
onclick: move |_| toggle.toggle(),
"toggle"
}
div {
onmounted: move |evt| {
async move {
loop {
tokio::time::sleep(Duration::from_millis(100)).await;
println!("{:?}", evt.get_client_rect().await);
}
}
},
width: "{count}px",
height: "{count}px",
style: "background-color: red",
}
}
}
} |
I do not recreate element itself but I do reposition it on the parent. |
Problem
MountedData
is the structure that providesget_client_rect
function to get position and size of the element.It can be stored somewhere by cloning
Rc<MountedData>
from theonmounted
callback.The
Rc<MountedData>
should point exact same element or theonmounted
callback should be called after the re-renderSteps To Reproduce
MountedData::get_clinet_rect()
function. It will cause panic.Expected behavior
The stored
Rc<MountedData>
should return values properly. or the callback registered on theonmounted
should called after re-rendering.Environment:
0.5.1
1.77.2
Windows
Desktop
Questionnaire
The text was updated successfully, but these errors were encountered: