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

Lifetime error when using nested signals #400

Closed
jafioti opened this issue Mar 25, 2022 · 2 comments · Fixed by #519
Closed

Lifetime error when using nested signals #400

jafioti opened this issue Mar 25, 2022 · 2 comments · Fixed by #519
Labels
A-reactivity Area: reactivity and state handling C-bug Category: bug, something isn't working

Comments

@jafioti
Copy link

jafioti commented Mar 25, 2022

I am getting a lifetime error when using multiple layers of nested signals and Indexed

This code produces the error:

#[component]
pub fn TempComponent<G: Html>(ctx: Scope) -> View<G> {
    let original = create_signal(ctx, vec![create_signal(ctx, vec![create_signal(ctx, 1)])]);
    view!{ctx,
        Indexed {
            iterable: original,
            view: |ctx, var| view! {ctx,
                InnerComponent(var)
            }
        }
    }
}

#[component]
fn InnerComponent<'a, G: Html>(ctx: Scope<'a>, var: &'a Signal<Vec<&'a Signal<i32>>>) -> View<G> {
    view!{ctx, 

    }
}

This code works fine:

#[component]
pub fn TempComponent<G: Html>(ctx: Scope) -> View<G> {
    let original = create_signal(ctx, vec![create_signal(ctx, 1)]);
    view!{ctx,
        Indexed {
            iterable: original,
            view: |ctx, var| view! {ctx,
                InnerComponent(var)
            }
        }
    }
}

#[component]
fn InnerComponent<'a, G: Html>(ctx: Scope<'a>, var: &'a Signal<i32>) -> View<G> {
    view!{ctx, 

    }
}
  • Sycamore: master
@jafioti jafioti added the C-bug Category: bug, something isn't working label Mar 25, 2022
@lukechu10 lukechu10 added the A-reactivity Area: reactivity and state handling label Mar 25, 2022
@lukechu10
Copy link
Member

Hmm this seems to be some kind of issue with Rust's lifetime shortening algorithm. This works:

#[component]
pub fn TempComponent<G: Html>(cx: Scope) -> View<G> {
    let original = create_signal(cx, vec![create_signal(cx, vec![create_signal(cx, 1)])]);
    view! { cx,
        Indexed {
            iterable: original,
            view: |cx, var| view! { cx,
                InnerComponent(var)
            }
        }
    }
}

#[component]
fn InnerComponent<'a, 'b: 'a, G: Html>(
    cx: Scope<'a>,
    _var: &'b Signal<Vec<&'b Signal<i32>>>,
) -> View<G> {
    view! {cx,

    }
}

@lukechu10
Copy link
Member

I'll leave this open for now because it's kind of weird that the first doesn't work but the second works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reactivity Area: reactivity and state handling C-bug Category: bug, something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants