diff --git a/packages/native-core/src/passes.rs b/packages/native-core/src/passes.rs index fe774f7ba..bdc7c7e5b 100644 --- a/packages/native-core/src/passes.rs +++ b/packages/native-core/src/passes.rs @@ -215,8 +215,10 @@ fn resolve_downward_pass + ?Sized>( while let Some(id) = dirty.pop_front() { let (node, parent) = tree.node_parent_mut(id).unwrap(); let result = pass.pass(node, parent, ctx); - if result.mark_dirty || result.progress { + if result.mark_dirty { nodes_updated.insert(id); + } + if result.mark_dirty || result.progress { for id in tree.children_ids(id).unwrap() { if result.mark_dirty { for dependant in pass.dependants() { diff --git a/packages/native-core/src/real_dom.rs b/packages/native-core/src/real_dom.rs index 5c4771f0f..7ee8926d4 100644 --- a/packages/native-core/src/real_dom.rs +++ b/packages/native-core/src/real_dom.rs @@ -164,7 +164,10 @@ impl RealDom { } /// Updates the dom with some mutations and return a set of nodes that were updated. Pass the dirty nodes to update_state. - pub fn apply_mutations(&mut self, mutations: Mutations) -> DirtyNodeStates { + pub fn apply_mutations( + &mut self, + mutations: Mutations, + ) -> (DirtyNodeStates, FxHashMap) { let mut nodes_updated: FxHashMap = FxHashMap::default(); for template in mutations.templates { let mut template_root_ids = Vec::new(); @@ -348,7 +351,7 @@ impl RealDom { } let dirty_nodes = DirtyNodeStates::default(); - for (n, mask) in nodes_updated { + for (&n, mask) in &nodes_updated { // remove any nodes that were created and then removed in the same mutations from the dirty nodes list if self.tree.contains(n) { for (m, p) in S::MASKS.iter().zip(S::PASSES.iter()) { @@ -359,7 +362,7 @@ impl RealDom { } } - dirty_nodes + (dirty_nodes, nodes_updated) } /// Update the state of the dom, after appling some mutations. This will keep the nodes in the dom up to date with their VNode counterparts. diff --git a/packages/native-core/src/state.rs b/packages/native-core/src/state.rs index 09ae4333b..365aa151c 100644 --- a/packages/native-core/src/state.rs +++ b/packages/native-core/src/state.rs @@ -221,10 +221,8 @@ pub trait State: Default + Clone + 'static { tree: &mut T, ctx: SendAnyMap, ) -> FxDashSet { - let set = FxDashSet::default(); let passes = Self::PASSES.iter().collect(); - resolve_passes(tree, dirty, passes, ctx); - set + resolve_passes(tree, dirty, passes, ctx) } } diff --git a/packages/tui/src/lib.rs b/packages/tui/src/lib.rs index 56a34a047..8b35ac54c 100644 --- a/packages/tui/src/lib.rs +++ b/packages/tui/src/lib.rs @@ -6,7 +6,7 @@ use crossterm::{ }; use futures_channel::mpsc::unbounded; use dioxus_core::*; -use dioxus_native_core::{real_dom::RealDom, NodeId, SendAnyMap, FxDashSet}; +use dioxus_native_core::{real_dom::RealDom, NodeId, SendAnyMap, FxDashSet, NodeMask}; use focus::FocusState; use futures::{ channel::mpsc::{UnboundedReceiver, UnboundedSender}, @@ -90,7 +90,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) { { let mut rdom = rdom.borrow_mut(); let mutations = dom.rebuild(); - let to_update = rdom.apply_mutations(mutations); + let (to_update,_) = rdom.apply_mutations(mutations); let mut any_map = SendAnyMap::new(); any_map.insert(taffy.clone()); let _to_rerender = rdom.update_state(to_update, any_map); @@ -135,16 +135,14 @@ fn render_vdom( let mut to_rerender =FxDashSet::default(); to_rerender.insert(NodeId(0)); let mut updated = true; - + loop { /* -> render the nodes in the right place with tui/crossterm -> wait for changes -> resolve events -> lazily update the layout and style based on nodes changed - use simd to compare lines for diffing? - todo: lazy re-rendering */ @@ -244,11 +242,16 @@ fn render_vdom( let mutations = vdom.render_immediate(); handler.prune(&mutations, &rdom); // updates the dom's nodes - let to_update = rdom.apply_mutations(mutations); + let (to_update, dirty) = rdom.apply_mutations(mutations); // update the style and layout let mut any_map = SendAnyMap::new(); any_map.insert(taffy.clone()); to_rerender = rdom.update_state(to_update, any_map); + for (id, mask) in dirty { + if mask.overlaps(&NodeMask::new().with_text()) { + to_rerender.insert(id); + } + } } } diff --git a/packages/tui/src/node.rs b/packages/tui/src/node.rs index 33f74a011..26ea4412e 100644 --- a/packages/tui/src/node.rs +++ b/packages/tui/src/node.rs @@ -54,7 +54,8 @@ impl NodeDepState for PreventDefault { dioxus_native_core::node_ref::AttributeMask::Static(&sorted_str_slice!([ "dioxus-prevent-default" ])), - ); + ) + .with_listeners(); fn reduce( &mut self,