You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried to migrate to 0.7 and I think I've stumbled upon a bug when using a generic component to read resources. The code builds without problem but a Uncaught RuntimeError: unreachable executed occurs when rendering the Suspense.
Leptos Dependencies
leptos = { version = "0.7.0-beta5", features = ["nightly"] }
leptos_axum = { version = "0.7.0-beta5", optional = true }
leptos_meta = { version = "0.7.0-beta5" }
leptos_router = { version = "0.7.0-beta5", features = ["nightly"] }
To Reproduce
Here is a minimal example to reproduce the issue. The bug depends on the children of , in this example it only occurs when let signal = RwSignal::new(0); is present in . In my code, I also got issues when an is in the children.
use leptos::prelude::*;
use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title};
use leptos_router::{
components::{Route, Router, Routes},
StaticSegment,
};
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
#[server]
pub async fn string_data() -> Result<String, ServerFnError> {
Ok(String::from("hello world"))
}
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
view! {
// injects a stylesheet into the document <head>
// id=leptos means cargo-leptos will hot-reload this stylesheet
<Stylesheet id="leptos" href="/pkg/reproduce-leptos-0-7-beta5.css"/>
// sets the document title
<Title text="Welcome to Leptos"/>
// content for this welcome page
<Router>
<main>
<Routes fallback=|| "Page not found.".into_view()>
<Route path=StaticSegment("") view=HomePage/>
<Route path=StaticSegment("test") view=Test/>
</Routes>
</main>
</Router>
}
}
/// Renders the home page of your application.
#[component]
fn HomePage() -> impl IntoView {
view! {
<h1>"Welcome to Leptos!"</h1>
<a href="/test">"Test page"</a>
}
}
/// Renders the test page.
#[component]
fn Test() -> impl IntoView {
// Creates a reactive value to update the button
let count = RwSignal::new(0);
let on_click = move |_| *count.write() += 1;
let resource = Resource::new(
move || (),
move |_| string_data()
);
view! {
<h1>"Welcome to Leptos!"</h1>
<button on:click=on_click>"Click Me: " {count}</button>
<SuspenseUnpack resource=resource let:value>
<ValueDisplay value=value.clone()/>
</SuspenseUnpack>
}
}
/// Renders the resource value
#[component]
fn ValueDisplay(
value: String,
) -> impl IntoView {
let signal = RwSignal::new(0);
view! {
<div>{value}</div>
}
}
#[component]
pub fn SuspenseUnpack<
T: Clone + Send + Sync + 'static,
V: IntoView + 'static,
F: Fn(&T) -> V + Clone + Send + Sync + 'static,
>(
resource: Resource<Result<T, ServerFnError>>,
children: F,
) -> impl IntoView {
let children = StoredValue::new(children);
view! {
<Suspense>
{
move || Suspend::new(async move {
match &resource.await {
Ok(value) => Either::Left(children.with_value(|children| children(value))),
Err(_e) => Either::Right(view! { <div>"Error"</div> }),
}
})
}
</Suspense>
}
}
Let me know if I can help in any way and thanks a lot for your work :)
The text was updated successfully, but these errors were encountered:
These kinds of nested changes should be allowed from a DX perspective, it's just the new arena implementation which accidentally assumes they don't. Allowing them to work as intended probably involves adding an extra layer of indirection here by adding an additional Arc<Mutex<_>> around a StoredValue so that we can clone the StoredValue out of the arena, then work with it, rather than just taking a lock on the whole arena.
Given that I may want to refactor the way that signals etc. use StoredValue so that they are not paying that same cost.
Thanks a lot for the quick reply, the workaround indeed fixed the issue 👍
gbj
changed the title
[0.7] Runtime error when reading resource in generic component
[0.7] Storing a new item in the arena while holding a shared reference to an arena-allocated item fails
Sep 17, 2024
Hello,
I've tried to migrate to 0.7 and I think I've stumbled upon a bug when using a generic component to read resources. The code builds without problem but a
Uncaught RuntimeError: unreachable executed
occurs when rendering the Suspense.Leptos Dependencies
leptos = { version = "0.7.0-beta5", features = ["nightly"] }
leptos_axum = { version = "0.7.0-beta5", optional = true }
leptos_meta = { version = "0.7.0-beta5" }
leptos_router = { version = "0.7.0-beta5", features = ["nightly"] }
To Reproduce
Here is a minimal example to reproduce the issue. The bug depends on the children of , in this example it only occurs when
let signal = RwSignal::new(0);
is present in . In my code, I also got issues when an is in the children.Let me know if I can help in any way and thanks a lot for your work :)
The text was updated successfully, but these errors were encountered: