Skip to content
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

Parent element re-mounts when child updates #3343

Open
industrylol opened this issue Dec 11, 2024 · 0 comments · May be fixed by #3346
Open

Parent element re-mounts when child updates #3343

industrylol opened this issue Dec 11, 2024 · 0 comments · May be fixed by #3346
Assignees
Labels
bug Something isn't working core relating to the core implementation of the virtualdom

Comments

@industrylol
Copy link

Problem

Updates to signals in children seems to cause the parent to re-mount triggering the onmounted event to re-occur even though it should already be in the DOM.

This seems to be caused by #3271, reverting to a previous commit does not show this behavior.

I was trying to implement a virtual scroll element and my scroll container was being remounted continuously, it had been working in prior 0.6 alphas. Extracting the child elements and the counter into their own component does resolve the issue in simple components, but doesn't in more complex cases.

Steps To Reproduce

Steps to reproduce the behavior:

use dioxus::prelude::*;

fn main() {
    dioxus::launch(App);
}

#[component]
fn App() -> Element {
    let mut counter = use_signal(|| 0);
    let mut saved_element = use_signal(|| None);
    rsx! {
        div {
            onmounted: move |element: Event<MountedData>| {
                println!("MOUNTING");
                saved_element.set(Some(element.data()));
            },
            button {
                onclick: move |_| {
                    *counter.write() += 1;
                },
                "INCREMENT"
            }
            div { "{counter}" }
        }
    }
}

The same issue can be seen on your read_size example if you add logging to the mount event:
https://github.com/DioxusLabs/dioxus/blob/main/examples/read_size.rs

Expected behavior

The parent should be mounted once and stay mounted, only its children should update when a relevant signal is written to.

Screenshots

image
image

Environment:

  • Dioxus version: 0.6.0
  • Rust version: 1.83.0
  • OS info: Windows 11
  • App platform: Desktop

Questionnaire

@ealmloff ealmloff self-assigned this Dec 12, 2024
@ealmloff ealmloff added bug Something isn't working core relating to the core implementation of the virtualdom labels Dec 12, 2024
@ealmloff ealmloff linked a pull request Dec 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core relating to the core implementation of the virtualdom
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants