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

Warn when signals are used in a higher scope then they are created in #2672

Closed
ealmloff opened this issue Jul 22, 2024 · 0 comments · Fixed by #2771
Closed

Warn when signals are used in a higher scope then they are created in #2672

ealmloff opened this issue Jul 22, 2024 · 0 comments · Fixed by #2771
Assignees
Labels
core relating to the core implementation of the virtualdom tweak Small changes to improve experience
Milestone

Comments

@ealmloff
Copy link
Member

Feature Request

We should warn the user if they try to move a signal up through the component tree. Moving a signal up through the tree can cause issues with infinite reruns and signals in children being dropped before the parent

Implement Suggestion

Log a tracing::warn when something like this happens:

fn MyComponent() -> Element {
    let child_signal = use_signal(|| None);

    rsx! {
        // A signal from a child is read or written to in a parent scope (with a lower height)
        "{child_signal:?}"
        IncrementButton {
            child_signal
        }
    }
}

#[component]
fn IncrementButton(mut child_signal: Signal<Option<Signal<i32>>>) -> Element {
    let signal_owned_by_child = use_signal(|| 0);
    // Don't do this: it may cause issues if you drop the child component
    child_signal.set(Some(signal_owned_by_child));

    todo!()
}
@ealmloff ealmloff added core relating to the core implementation of the virtualdom tweak Small changes to improve experience labels Jul 22, 2024
@jkelleyrtp jkelleyrtp added this to the 0.6.0 milestone Jul 25, 2024
@ealmloff ealmloff self-assigned this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core relating to the core implementation of the virtualdom tweak Small changes to improve experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants