Skip to content

Commit 47f3910

Browse files
committed
signals: Rebuild stale global cache entries automatically
1 parent 7454fc2 commit 47f3910

File tree

1 file changed

+16
-1
lines changed
  • packages/signals/src/global

1 file changed

+16
-1
lines changed

packages/signals/src/global/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,27 @@ where
182182
let context = get_global_context();
183183

184184
// Get the entry if it already exists
185+
let mut evicted_stale_entry = false;
185186
{
186187
let read = context.map.borrow();
187188
if let Some(signal) = read.get(&key) {
188-
return signal.downcast_ref::<T>().cloned().unwrap();
189+
if let Some(signal) = signal.downcast_ref::<T>() {
190+
return signal.clone();
191+
}
192+
evicted_stale_entry = true;
193+
#[cfg(debug_assertions)]
194+
tracing::warn!(
195+
?key,
196+
stored_type = ?signal.type_id(),
197+
expected_type = std::any::type_name::<T>(),
198+
expected_type_id = ?std::any::TypeId::of::<T>(),
199+
"Global signal cache entry type mismatch; rebuilding entry"
200+
);
189201
}
190202
}
203+
if evicted_stale_entry {
204+
context.map.borrow_mut().remove(&key);
205+
}
191206
// Otherwise, create it
192207
// Constructors are always run in the root scope
193208
let signal = dioxus_core::Runtime::current().in_scope(ScopeId::ROOT, || {

0 commit comments

Comments
 (0)