Browse Source

fix double drop of bubble id

Evan Almloff 1 năm trước cách đây
mục cha
commit
02456c1068

+ 3 - 1
packages/core/src/arena.rs

@@ -162,7 +162,9 @@ impl VirtualDom {
             let element_refs_slab = &mut self.element_refs;
             for element_ref in element_refs.drain(..) {
                 println!("Dropping element ref {:?}", element_ref);
-                element_refs_slab[element_ref.0].template = None;
+                if let Some(element_ref) = element_refs_slab.get_mut(element_ref.0) {
+                    element_ref.template = None;
+                }
             }
         }
 

+ 2 - 1
packages/core/src/virtual_dom.rs

@@ -371,7 +371,8 @@ impl VirtualDom {
             // Loop through each dynamic attribute (in a depth first order) in this template before moving up to the template's parent.
             while let Some(el_ref) = parent_path {
                 // safety: we maintain references of all vnodes in the element slab
-                let template = unsafe { &*el_ref.template.unwrap() };
+                let template =
+                    unsafe { &*el_ref.template.expect("template reference should be valid") };
                 let node_template = template.template.get();
                 let target_path = el_ref.path;
 

+ 5 - 1
packages/core/tests/event_propagation.rs

@@ -42,7 +42,11 @@ fn app(cx: Scope) -> Element {
                 *CLICKS.lock().unwrap() += 1;
             },
 
-            problematic_child {}
+            vec![
+                render! {
+                    problematic_child {}
+                }
+            ].into_iter()
         }
     }
 }