-
Notifications
You must be signed in to change notification settings - Fork 153
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 views #387
Comments
This regression was introduced by 9fdff59 because it adds an addition Unfortunately, this change is necessary to prevent memory leaks and it seems like it interferes with Rust's borrow checker. I suspect it has something to do with the invariance of the lifetime parameter on In other words, the following works: #[component]
pub fn TempComponent<G: Html>(ctx: Scope) -> View<G> {
let action = |_| {
ctx.create_signal(0);
};
view!{ ctx,
({
view!{ ctx,
input (on:click=action)
}
})
}
} I'm guessing because If somebody can figure this out, that would be greatly appreciated! |
But for your specific use case, since the interpolated value is not actually reactive, you can just create the inner view outside of the outer view like so: #[component]
pub fn TempComponent<G: Html>(ctx: Scope) -> View<G> {
let action = |_| ctx.spawn_local(async move {});
let inner = view!{ ctx,
input (on:click=action)
};
view!{ ctx,
(inner)
}
} |
Eureka! This is because of rustc non-lexical-lifetimes "migration mode". If you add |
Rust tracking issue for turning off nll migration mode: rust-lang/rust#58781 |
Release v0.8 now relies on nll mode so I will close this issue. Please create a new issue if your problem is not resolved. |
When using nested views and an action callback, a lifetime error is thrown.
Steps to reproduce the behavior:
Open any sycamore project and paste:
Expected that no lifetime error is thrown since this is valid code.
The text was updated successfully, but these errors were encountered: