From 5b6f9d6b80ef06c83a55a5399d3ddcd7e29479df Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 6 Jan 2024 08:58:49 -0600 Subject: [PATCH] fix merge --- examples/spread.rs | 7 ++----- packages/core/src/diff.rs | 18 +++++++++++------- packages/core/src/error_boundary.rs | 4 ++-- packages/core/src/lib.rs | 11 +++++------ packages/core/src/nodes.rs | 2 +- packages/core/src/virtual_dom.rs | 13 +++++++------ 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/examples/spread.rs b/examples/spread.rs index b13124a5f..45bdc90af 100644 --- a/examples/spread.rs +++ b/examples/spread.rs @@ -15,7 +15,7 @@ fn app(cx: Scope) -> Element { extra_data: "hello{1}", extra_data2: "hello{2}", height: "10px", - left: 1, + left: 1 } } } @@ -23,10 +23,7 @@ fn app(cx: Scope) -> Element { #[component] fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> { render! { - audio { - ..cx.props.attributes, - "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" - } + audio { ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" } } } diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs index 756922e4d..a116aee4d 100644 --- a/packages/core/src/diff.rs +++ b/packages/core/src/diff.rs @@ -126,10 +126,11 @@ impl<'b> VirtualDom { .dynamic_attrs .iter() .zip(right_template.dynamic_attrs.iter()) - .for_each(|(left_attr, right_attr)| { + .enumerate() + .for_each(|(idx, (left_attr, right_attr))| { // Move over the ID from the old to the new - let mounted_element = left_attr.mounted_element.get(); - right_attr.mounted_element.set(mounted_element); + let mounted_id = left_attr.mounted_element.get(); + right_attr.mounted_element.set(mounted_id); match (&left_attr.ty, &right_attr.ty) { (AttributeType::Single(left), AttributeType::Single(right)) => { @@ -149,9 +150,12 @@ impl<'b> VirtualDom { left.namespace, mounted_id, ), - std::cmp::Ordering::Greater => { - self.write_attribute(right, mounted_id) - } + std::cmp::Ordering::Greater => self.write_attribute( + right_template, + right, + idx, + mounted_id, + ), std::cmp::Ordering::Equal => { self.diff_attribute(left, right, mounted_id) } @@ -163,7 +167,7 @@ impl<'b> VirtualDom { } (None, Some(_)) => { let right = right_iter.next().unwrap(); - self.write_attribute(right, mounted_id) + self.write_attribute(right_template, right, idx, mounted_id) } (None, None) => break, } diff --git a/packages/core/src/error_boundary.rs b/packages/core/src/error_boundary.rs index d42f59395..717e1baa7 100644 --- a/packages/core/src/error_boundary.rs +++ b/packages/core/src/error_boundary.rs @@ -334,10 +334,10 @@ where } } } -impl<'a> Properties for ErrorBoundaryProps<'a> { +impl<'a> Properties<'a> for ErrorBoundaryProps<'a> { type Builder = ErrorBoundaryPropsBuilder<'a, ((), ())>; const IS_STATIC: bool = false; - fn builder() -> Self::Builder { + fn builder(_: &'a ScopeState) -> Self::Builder { ErrorBoundaryProps::builder() } unsafe fn memoize(&self, _: &Self) -> bool { diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index 1c41c42de..c478ec657 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -90,12 +90,11 @@ pub mod prelude { pub use crate::innerlude::{ consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, has_context, provide_context, provide_context_to_scope, provide_root_context, push_future, - remove_future, schedule_update_any, spawn, spawn_forever, suspend, throw, - use_error_boundary, AnyValue, AnyValue, Attribute, AttributeType, Component, Element, - ErrorBoundary, Event, EventHandler, Fragment, HasAttributes, IntoAttributeValue, - IntoDynNode, LazyNodes, MountedAttribute, Properties, Runtime, RuntimeGuard, Scope, - ScopeId, ScopeState, Scoped, TaskId, Template, TemplateAttribute, TemplateNode, Throw, - VNode, VirtualDom, + remove_future, schedule_update_any, spawn, spawn_forever, suspend, use_error_boundary, + AnyValue, Attribute, AttributeType, Component, Element, ErrorBoundary, Event, EventHandler, + Fragment, HasAttributes, IntoAttributeValue, IntoDynNode, LazyNodes, MountedAttribute, + Properties, Runtime, RuntimeGuard, Scope, ScopeId, ScopeState, Scoped, TaskId, Template, + TemplateAttribute, TemplateNode, Throw, VNode, VirtualDom, }; } diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index 91ace558f..6396504a4 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -92,7 +92,7 @@ impl<'a> VNode<'a> { template: Template<'static>, root_ids: bumpalo::collections::Vec<'a, ElementId>, dynamic_nodes: &'a [DynamicNode<'a>], - dynamic_attrs: &'a [Attribute<'a>], + dynamic_attrs: &'a [MountedAttribute<'a>], ) -> Self { Self { key, diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 5a9e29683..28ccbc76a 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -5,13 +5,13 @@ use crate::{ any_props::VProps, arena::{ElementId, ElementRef}, - innerlude::{AttributeType, DirtyScope, ErrorBoundary, Mutations, Scheduler, SchedulerMsg}, + innerlude::{DirtyScope, ErrorBoundary, Mutations, Scheduler, SchedulerMsg}, mutations::Mutation, nodes::RenderReturn, nodes::{Template, TemplateId}, runtime::{Runtime, RuntimeGuard}, scopes::{ScopeId, ScopeState}, - Attribute, AttributeValue, Element, Event, Scope, VNode, + AttributeValue, Element, Event, Scope, VNode, }; use futures_util::{pin_mut, StreamExt}; use rustc_hash::{FxHashMap, FxHashSet}; @@ -371,7 +371,6 @@ impl VirtualDom { .get(parent_path.template.0) .cloned() .map(|el| (*parent_path, el)); - let mut listeners = vec![]; // We will clone this later. The data itself is wrapped in RC to be used in callbacks if required let uievent = Event { @@ -383,6 +382,8 @@ impl VirtualDom { if bubbles { // Loop through each dynamic attribute (in a depth first order) in this template before moving up to the template's parent. while let Some((path, el_ref)) = parent_node { + let mut listeners = vec![]; + // safety: we maintain references of all vnodes in the element slab let template = unsafe { el_ref.unwrap().as_ref() }; let node_template = template.template.get(); @@ -396,7 +397,7 @@ impl VirtualDom { attr.ty.for_each(|attribute| { if attribute.name.trim_start_matches("on") == name { if let AttributeValue::Listener(listener) = &attribute.value { - listeners.push(&listener); + listeners.push(listener); } } }); @@ -412,7 +413,7 @@ impl VirtualDom { // Now that we've accumulated all the parent attributes for the target element, call them in reverse order // We check the bubble state between each call to see if the event has been stopped from bubbling - for listener in listeners.drain(..).rev() { + for listener in listeners.into_iter().rev() { let origin = path.scope; self.runtime.scope_stack.borrow_mut().push(origin); self.runtime.rendering.set(false); @@ -451,7 +452,7 @@ impl VirtualDom { let mut should_stop = false; attr.ty.for_each(|attribute| { if attribute.name.trim_start_matches("on") == name { - if let AttributeValue::Listener(listener) = &attr.value { + if let AttributeValue::Listener(listener) = &attribute.value { let origin = path.scope; self.runtime.scope_stack.borrow_mut().push(origin); self.runtime.rendering.set(false);