mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
fix: leaking stored values (#683)
This commit is contained in:
parent
d6e166f105
commit
b988ee85f4
3 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -329,7 +329,6 @@ pub fn create_signal<T>(
|
|||
value: T,
|
||||
) -> (ReadSignal<T>, WriteSignal<T>) {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue