diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index 010c63b03..8db5efe56 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -609,7 +609,7 @@ impl ScopeState { /// Create a subscription that schedules a future render for the reference component /// - /// ## Notice: you should prefer using prepare_update and get_scope_id + /// ## Notice: you should prefer using schedule_update_any and scope_id pub fn schedule_update(&self) -> Arc { let (chan, id) = (self.tasks.sender.clone(), self.scope_id()); Arc::new(move || { @@ -1000,12 +1000,11 @@ impl TaskQueue { fn remove(&self, id: TaskId) { if let Ok(mut tasks) = self.tasks.try_borrow_mut() { let _ = tasks.remove(&id); + if let Some(task_map) = self.task_map.borrow_mut().get_mut(&id.scope) { + task_map.remove(&id); + } } - // the task map is still around, but it'll be removed when the scope is unmounted - if let Some(task_map) = self.task_map.borrow_mut().get_mut(&id.scope) { - task_map.remove(&id); - } } pub(crate) fn has_tasks(&self) -> bool { diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 2b1de0767..333fef513 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -337,29 +337,12 @@ impl VirtualDom { let scopes = &mut self.scopes; let task_poll = poll_fn(|cx| { - // - let mut any_pending = false; - let mut tasks = scopes.tasks.tasks.borrow_mut(); - let mut to_remove = vec![]; + tasks.retain(|_, task| task.as_mut().poll(cx).is_pending()); - // this would be better served by retain - for (id, task) in tasks.iter_mut() { - if task.as_mut().poll(cx).is_ready() { - to_remove.push(*id); - } else { - any_pending = true; - } - } - - for id in to_remove { - tasks.remove(&id); - } - - // Resolve the future if any singular task is ready - match any_pending { - true => Poll::Pending, - false => Poll::Ready(()), + match tasks.is_empty() { + true => Poll::Ready(()), + false => Poll::Pending, } }); diff --git a/packages/fermi/src/root.rs b/packages/fermi/src/root.rs index c7c234ddb..f77930c75 100644 --- a/packages/fermi/src/root.rs +++ b/packages/fermi/src/root.rs @@ -74,6 +74,13 @@ impl AtomRoot { } } else { log::trace!("no atoms found for {:?}", ptr); + atoms.insert( + ptr, + Slot { + value: Rc::new(value), + subscribers: HashSet::new(), + }, + ); } }