瀏覽代碼

set the scope stack correctly

Evan Almloff 1 年之前
父節點
當前提交
a2c7b69a1d
共有 4 個文件被更改,包括 9 次插入9 次删除
  1. 2 5
      packages/core/src/create.rs
  2. 0 2
      packages/core/src/diff.rs
  3. 1 1
      packages/core/src/runtime.rs
  4. 6 1
      packages/core/src/scope_arena.rs

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

@@ -65,11 +65,8 @@ impl<'b> VirtualDom {
     /// Create a new template [`VNode`] and write it to the [`Mutations`] buffer.
     ///
     /// This method pushes the ScopeID to the internal scopestack and returns the number of nodes created.
-    pub(crate) fn create_scope(&mut self, scope: ScopeId, template: &'b VNode<'b>) -> usize {
-        self.runtime.scope_stack.borrow_mut().push(scope);
-        let out = self.create(template);
-        self.runtime.scope_stack.borrow_mut().pop();
-        out
+    pub(crate) fn create_scope(&mut self, _scope: ScopeId, template: &'b VNode<'b>) -> usize {
+        self.create(template)
     }
 
     /// Create this template and write its mutations

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

@@ -15,7 +15,6 @@ use DynamicNode::*;
 
 impl<'b> VirtualDom {
     pub(super) fn diff_scope(&mut self, scope: ScopeId) {
-        self.runtime.scope_stack.borrow_mut().push(scope);
         let scope_state = &mut self.get_scope(scope).unwrap();
         unsafe {
             // Load the old and new bump arenas
@@ -46,7 +45,6 @@ impl<'b> VirtualDom {
                 (Aborted(l), Ready(r)) => self.replace_placeholder(l, [r]),
             };
         }
-        self.runtime.scope_stack.borrow_mut().pop();
     }
 
     fn diff_ok_to_err(&mut self, l: &'b VNode<'b>, p: &'b VPlaceholder) {

+ 1 - 1
packages/core/src/runtime.rs

@@ -45,7 +45,7 @@ pub struct Runtime {
     pub(crate) scope_contexts: RefCell<Vec<Option<ScopeContext>>>,
     pub(crate) scheduler: Rc<Scheduler>,
 
-    // While diffing we need some sort of way of breaking off a stream of suspended mutations.
+    // We use this to track the current scope
     pub(crate) scope_stack: RefCell<Vec<ScopeId>>,
 }
 

+ 6 - 1
packages/core/src/scope_arena.rs

@@ -46,6 +46,7 @@ impl VirtualDom {
     }
 
     pub(crate) fn run_scope(&mut self, scope_id: ScopeId) -> &RenderReturn {
+        self.runtime.scope_stack.borrow_mut().push(scope_id);
         // Cycle to the next frame and then reset it
         // This breaks any latent references, invalidating every pointer referencing into it.
         // Remove all the outdated listeners
@@ -94,6 +95,10 @@ impl VirtualDom {
         }
 
         // rebind the lifetime now that its stored internally
-        unsafe { allocated.extend_lifetime_ref() }
+        let result = unsafe { allocated.extend_lifetime_ref() };
+
+        self.runtime.scope_stack.borrow_mut().pop();
+
+        result
     }
 }