Bläddra i källkod

fix: make sure to set scope on none

Jonathan Kelley 2 år sedan
förälder
incheckning
6b41c9d193
2 ändrade filer med 10 tillägg och 1 borttagningar
  1. 2 0
      packages/core/src/create.rs
  2. 8 1
      packages/core/src/diff.rs

+ 2 - 0
packages/core/src/create.rs

@@ -337,6 +337,8 @@ impl<'b> VirtualDom {
         // Load up a ScopeId for this vcomponent
         let scope = self.load_scope_from_vcomponent(component);
 
+        component.scope.set(Some(scope));
+
         match unsafe { self.run_scope(scope).extend_lifetime_ref() } {
             Ready(t) => self.mount_component(scope, template, t, idx),
             Aborted(t) => self.mount_aborted(template, t),

+ 8 - 1
packages/core/src/diff.rs

@@ -212,8 +212,12 @@ impl<'b> VirtualDom {
     ) {
         let m = self.create_component_node(right_template, right, idx);
 
+        let pre_edits = self.mutations.edits.len();
+
         self.remove_component_node(left, true);
 
+        assert!(self.mutations.edits.len() > pre_edits);
+
         // We want to optimize the replace case to use one less mutation if possible
         // Since mutations are done in reverse, the last node removed will be the first in the stack
         // Instead of *just* removing it, we can use the replace mutation
@@ -873,7 +877,10 @@ impl<'b> VirtualDom {
     }
 
     fn remove_component_node(&mut self, comp: &VComponent, gen_muts: bool) {
-        let scope = comp.scope.take().unwrap();
+        let scope = comp
+            .scope
+            .take()
+            .expect("VComponents to always have a scope");
 
         match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
             RenderReturn::Ready(t) => {