-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
[0.6] Context not disposed with owner. #3450
Comments
ReproductionMain files/// Cargo.toml [package]
name = "leptos-context-not-disposed"
version = "0.1.0"
edition = "2021"
[profile.release]
codegen-units = 1
lto = true
[dependencies]
leptos = { version = "0.6.15", features = ["csr"] }
console_log = "1"
log = "0.4"
console_error_panic_hook = "0.1.7"
[dev-dependencies]
wasm-bindgen = "0.2"
wasm-bindgen-test = "0.3.0"
web-sys = "0.3"
/// main.rs use std::rc::{Rc, Weak};
use leptos::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| {
view! {
<App />
}
})
}
#[component]
pub fn App() -> impl IntoView {
let opened = create_rw_signal(true);
let rc_weak = create_rw_signal::<Option<Weak<i32>>>(None);
let messages = create_rw_signal(vec!["Press button to destroy SubComponent".to_string()]);
let handle_click = move |_| {
opened.set(!opened.get());
if !opened.get_untracked() {
leptos::set_timeout(
move || {
let rc_count = rc_weak
.get_untracked()
.map(|v| v.strong_count())
.unwrap_or(0);
messages.update(|messages| {
messages.push(format!("Done, Rc count: {}", rc_count));
});
},
std::time::Duration::from_secs(1),
);
}
};
view! {
<div>
<button on:click=handle_click>"Destroy SubComponent"</button>
<div>
<pre>{move || messages.get().join("\n")}</pre>
</div>
<Show when=move || opened.get()>
<SubComponent rc_weak=rc_weak messages=messages />
</Show>
</div>
}
}
#[component]
pub fn SubComponent(
rc_weak: RwSignal<Option<Weak<i32>>>,
messages: RwSignal<Vec<String>>,
) -> impl IntoView {
let context_value = Rc::new(1);
let value = Rc::downgrade(&context_value);
rc_weak.set(Some(value));
on_cleanup(move || {
log::info!("SubComponent cleanup");
messages.update(|messages| {
messages.push("SubComponent cleanup".to_string());
});
});
view! {
<Provider value=context_value>
<p>"Hello SubComponent"</p>
</Provider>
}
} Steps
|
It's 0 as expected on 0.7/current git main. I don't plan to work on a fix for 0.6 but would welcome a PR to the |
gbj
changed the title
Context not disposed with owner.
[0.6] Context not disposed with owner.
Jan 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
The context is not properly disposed of when the owner is disposed.
leptos/leptos_reactive/src/runtime.rs
Line 236 in b317d47
The text was updated successfully, but these errors were encountered: