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

Fix effect ordering and futures being run after scopes are dropped #1993

Merged
merged 12 commits into from
Mar 5, 2024

Conversation

ealmloff
Copy link
Member

This PR fixes futures that are rerun after scopes are dropped. The following example is broken on the main branch, but working on this branch:

use dioxus::prelude::*;

fn main() {
    launch(app);
}

fn app() -> Element {
    let mut vec = use_signal(|| vec![1, 2, 3]);

    let len = vec.len();

    rsx! {
        button {
            onclick: move |_| {
                let mut vec = vec.write();
                vec.push(len);
            },
            "Add"
        }
        button {
            onclick: move |_| {
                vec.pop();
            },
            "Remove"
        }
        for i in 0..len {
            Child {
                index: i,
                vec,
            }
        }
    }
}

#[component]
fn Child(index: usize, vec: Signal<Vec<usize>>) -> Element {
    let item = use_memo(move || vec.read()[index]);
    rsx! {
        div { "Item: {item}" }
    }
}

@ealmloff ealmloff added bug Something isn't working core relating to the core implementation of the virtualdom labels Feb 29, 2024
@ealmloff ealmloff marked this pull request as ready for review March 4, 2024 21:42
@ealmloff ealmloff force-pushed the fix-effect branch 2 times, most recently from d7ef43e to 2e3a730 Compare March 5, 2024 01:01
@jkelleyrtp
Copy link
Member

Note a huge huge fan of the complexity of combining tasks and scopes when pulling out work but it's something we can revisit - it's much more important that this functionality just works.

Thanks for taking this on. LGTM

@jkelleyrtp jkelleyrtp merged commit 608fec5 into main Mar 5, 2024
9 checks passed
@jkelleyrtp jkelleyrtp deleted the fix-effect branch March 5, 2024 19:18
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 this pull request may close these issues.

2 participants