diff --git a/packages/core/src/create.rs b/packages/core/src/create.rs index 4e7e35a1f..2e0d85f96 100644 --- a/packages/core/src/create.rs +++ b/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), diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs index 4112fdd55..81d000ba3 100644 --- a/packages/core/src/diff.rs +++ b/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) => {