From b988ee85f4d0b5b79e9b1d30e3d8f67427c5c28b Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Tue, 14 Mar 2023 11:06:36 -0400 Subject: [PATCH] fix: leaking stored values (#683) --- leptos_reactive/src/scope.rs | 6 +++++- leptos_reactive/src/signal.rs | 1 - leptos_reactive/src/stored_value.rs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/leptos_reactive/src/scope.rs b/leptos_reactive/src/scope.rs index 5e27f04..efc6798 100644 --- a/leptos_reactive/src/scope.rs +++ b/leptos_reactive/src/scope.rs @@ -4,7 +4,7 @@ use crate::{ node::NodeId, runtime::{with_runtime, RuntimeId}, suspense::StreamChunk, - PinnedFuture, ResourceId, SuspenseContext, + PinnedFuture, ResourceId, StoredValueId, SuspenseContext, }; use futures::stream::FuturesUnordered; use std::{collections::HashMap, fmt}; @@ -255,6 +255,9 @@ impl Scope { ScopeProperty::Resource(id) => { runtime.resources.borrow_mut().remove(id); } + ScopeProperty::StoredValue(id) => { + runtime.stored_values.borrow_mut().remove(id); + } } } } @@ -316,6 +319,7 @@ pub(crate) enum ScopeProperty { Signal(NodeId), Effect(NodeId), Resource(ResourceId), + StoredValue(StoredValueId), } /// Creating a [Scope](crate::Scope) gives you a disposer, which can be called diff --git a/leptos_reactive/src/signal.rs b/leptos_reactive/src/signal.rs index c4e223a..b1248ec 100644 --- a/leptos_reactive/src/signal.rs +++ b/leptos_reactive/src/signal.rs @@ -329,7 +329,6 @@ pub fn create_signal( value: T, ) -> (ReadSignal, WriteSignal) { let s = cx.runtime.create_signal(value); - //crate::macros::debug_warn!("created signal {:?} at {}", s.0.id, std::panic::Location::caller()); cx.with_scope_property(|prop| prop.push(ScopeProperty::Signal(s.0.id))); s } diff --git a/leptos_reactive/src/stored_value.rs b/leptos_reactive/src/stored_value.rs index ba9b0b7..25c8463 100644 --- a/leptos_reactive/src/stored_value.rs +++ b/leptos_reactive/src/stored_value.rs @@ -1,5 +1,5 @@ #![forbid(unsafe_code)] -use crate::{with_runtime, RuntimeId, Scope}; +use crate::{with_runtime, RuntimeId, Scope, ScopeProperty}; use std::{cell::RefCell, marker::PhantomData, rc::Rc}; slotmap::new_key_type! { @@ -418,6 +418,7 @@ where .insert(Rc::new(RefCell::new(value))) }) .unwrap_or_default(); + cx.with_scope_property(|prop| prop.push(ScopeProperty::StoredValue(id))); StoredValue { runtime: cx.runtime, id,